aywebdev
By:
aywebdev

Why is my site super laggy?

March 6, 2016 1.1k views
Server Optimization PHP MySQL Apache Scaling Ubuntu

Hello!

I own the website http://ninjackpot.com

I have upgraded the server, it is now flexible 40$/month and when 100 people are online the site gets super laggy and most of the times goes down.

Could anyone give any advice or suggestion on what i should improve and what may be the reason for this?

Thanks in advance!

1 comment
  • Seems like it is something that has to do with your code/overall optimization.
    4gb/2cpu host should flawlessly handle ~100 people.

    Anyway, first thing you should do is to study your logs. This is the only way to actually
    know where the shoe pinches.

    P.S. If your application is more cpu intensive rather than memory, splitting a droplet into two 2gb/2cpu is a way to sometimes improve overall performance. (For example one db vm and one for web server.)

    P.P.S.* Small advice considering your website.*
    Force redirect your users to https version.

    I apologize for not being word-perfect in English.

1 Answer

This type of question comes up more often when resizing is used to address a performance issue without the performance bottleneck being identified. Profiling applications and isolating the performance bottleneck is a very complex topic, as each phase of the process could lead to its own science.

When I handle this type of review for my projects, I typically start with the simpler questions. Is this a network issue or web server issue? Is the lagging aspect in the client side interaction, or server response? From there, I typically try loading static resources, and if those are not showing any issues loading, I can be confident the connection between myself and the server are okay.

Going into the application is a lot trickier. For php applications, you can use something like xdebug to get a profile of the way the code operates. If the application calls external resources ( e.g. a database, third party web service, etc ), you may find that the application spends a significant amount of time waiting on those. Other cases may show that it iterates through objects in the code repeatedly, or perhaps there is a buggy "sleep" call hidden in the code that someone forgot to remove.

In the frequent case of database bottlenecks, you can determine the longer running queries. There are a lot of resources out there for this alone, and work to optimize the database performance. It can easily impact things, as a query that ran quickly when the site first launched may have ballooned to several hundred thousand rows of data that get checked. Optimization in this department could range from adding some indexes in the database, to restructuring the code of the application and schema.

In short, you always want to start with testing the basics then profiling the application and service configurations to identify the performance bottlenecks as each case is different. This may not always be an easy issue to improve, but it will typically be the most appropriate one and provide you insight to issues that would impact your site at a larger scale as your viewer base increases over time. Hopefully this helps you get started.

Have another answer? Share your knowledge.