0

I recently ran into an issue I still cannot overcome.

So, I have a marketplace written in WordPress. After the development process, I tried to optimize the speed since the website loads many resources by nature.

I used WpFastestCache, which produces the .htaccess for me. The issue is this:

  • When mod_deflate and mod_expires are enabled, I get a pretty neat resources load time but a huge (around 10s !) TTFB.

    When mod_deflate and mod_expires are disabled, the TTFB drops to nearly nothing but I get a huge resource load time.

Is this something common or a unique case ?

  • Going to place a bounty on that one in 2 days so, keep that in mind ! – Konstantinos Koletsas Jun 22 '17 at 13:26
  • 1
    Caching plugins themselves can slow down Wordpress. Your best bet is caching outside PHP, at the web server level, or with a cache in front of the web server or even on your CDN. To enable this your caching headers need to be properly set, and you can only cache pages for anonymous users. This is [easy in Nginx](https://www.photographerstechsupport.com/tutorials/hosting-wordpress-on-aws-tutorial-part-4-wordpress-website-optimization/), but I'm not sure how to do it in Apache. – Tim Jun 22 '17 at 19:46
  • Thank you for your constructive comment Tim ! We are using Cloudflare which does not do well with compressions / minifications as apache does. – Konstantinos Koletsas Jun 22 '17 at 19:48
  • 2
    I haven't done any particular testing, but CloudFlare seems just fine for compression and minification. If your caching headers aren't set correctly they won't cache anything. They don't cache pages by default, you can make it with PageRules, but that's only useful for completely static pages. Caching pages on your server, and caching js/css/images on the CDN should help. I've done a lot of work in this area on my server, using Nginx. – Tim Jun 22 '17 at 20:09
  • What settings are used for mod_expires and mod_deflate? Perhaps your CPU can't cope with the compression levels, or the compressed files are written to a too slow disk. – JayMcTee Jun 29 '17 at 15:09
  • 1
    May you install sar, set it to a 5 minutes collection intervals, and make some tests with both modules enabled and disabled. Then paste your output of sar -A and indicate at what time you was testing with one method and at what time with the other method. Please ensure CPU and IO tests are enabled. You may even paste your /etc/fstab and lsblk output in order for us to better understand your IO and partitioning. Putting a bounty on a question won't be as useful as adding to the question as many details as you possibly can. ;) – Marco Jun 30 '17 at 11:52

1 Answers1

1

Given that you have problems both with compression enabled and with compression disabled, it sounds like the root cause of your problem is not the compression but rather somewhere else.

You explain how the symptoms change when you enable/disable compression. The change in symptoms is however only a minor change, and that change is what you should be expecting for most compression schemes.

When you have compression disabled you see that the first part of the response is produced quickly. It is entirely possible that the part of the response produced quickly is a header with static contents independent of the user data, and that may be why it is produced so quickly. The problematic part is that the data source takes a long time to produce the rest of the output.

Once the compression is introduced the symptoms change. Likely the header data is quickly delivered to the compression code, but in order to improve performance the compression code will wait for more data before it sends and of the data to the client. So a small amount of data will be sitting in that buffer for a while.

Some APIs permit the code producing the data to instruct the compression code to flush the buffered data, which if used here could make the symptom look the same as in the uncompressed setup. But if the data produced thus far isn't useful on its own it isn't worthwhile to flush the buffer.

What you should be looking into is why it takes such a long time before the last byte is send. I am guessing if you try to measure the time to last byte it will be roughly the same with and without compression.

How is the load on the server?

If the load on the server is high it may indicate it is busy doing CPU intensive tasks to produce responses to the requests it is receiving. It could also indicate that the server needs lots of I/O (which can usually be reduced by adding more RAM).

If the load on the server is low and it is still slow to respond it usually indicates that it is either waiting for network communication with another server (perhaps a DB or a DNS server is slow to respond). It could also indicate a bug somewhere in your code.

If you cannot deduce from server load, inspection of network traffic, or log files what is causing the slowness you may need to add more logging to your application in order to know what it is doing for such a long time.

kasperd
  • 29,894
  • 16
  • 72
  • 122
  • 2
    Thank you for contributing. A plethora of things went wrong actually. I found a ton of bottlenecks on the database, the homepage itself used to run 500 queries on load (60 duplicates !!!). As this wasn't enough, it was firing around 8 HTTP requests to youtube! Problem solved, thank you for your precious help. – Konstantinos Koletsas Jul 04 '17 at 08:03