Learn about Centmin Mod LEMP Stack today
Register Now

Reduce initial server response time

Discussion in 'Web Development & Web Performance' started by adamus007p, Oct 11, 2022.

  1. adamus007p

    adamus007p Member

    357
    18
    18
    Feb 8, 2019
    Ratings:
    +35
    Local Time:
    5:00 AM
    Hello, when I use PageSpeed Insights or Gtmetix or use Chrome and developer tools and make a Lighthouse to audit I see that there is a Reduce initial server response time.


    How to increase it? or maybe see if there is a problem on server side?

    I use Cloudflare and RS server from Netcup.

    The problem is not all the time but i see it in different times.

    I would be grateful for any ideas how to check the website from server side.


    I did not noticed it before, I was updating a centmin server and application too (to inscrese core vitats).
    I run there ecommerce - Prestashop.

    Code (Text):
    cminfo
    ------------------------------------------------------------------
     Centmin Mod Quick Info:
    ------------------------------------------------------------------
    Server Location Info
      city: Nuremberg
      region: Bavaria
      country: DE
      org: netcup GmbH
      timezone Europe/Berlin
    
    Processors physical = 1, cores = 4, virtual = 4, hyperthreading = no
    
          4  1996.249
          4  AMD EPYC 7702P 64-Core Processor
          4  512 KB
    
     System Up Since:       2022-06-09 18:09:21
     System Uptime:         up 17 weeks, 3 days, 22 hours, 56 minutes
     MySQL Server Started   2022-09-30 12:32:21
     MySQL Uptime:          10 days 4 hours 33 min 30 sec
     MySQL Uptime (secs):   880410
     Server Type:           kvm
     CentOS Version:        7.9
     Centmin Mod:           124.00stable.s54
     Nginx PageSpeed:       OFF
     Nginx Version:         1.21.6 (031022-221318-centos7-kvm-f6624e7-br-6e975bc)
     PHP-FPM Version:       7.4.32
     MariaDB Version:       10.3.36
     CSF Firewall:          v14.17
     Memcached Server:      1.6.5
     NSD Version:            -
     Siege Version:         4.0.4
     Maldet Version:        not installed
     ClamAV Version:        not installed
     ElasticSearch:         not installed
    



    Please advise which commanrds to run to check it to see if the problem is on server side.
    I remember that VPS there were problems with performance, RS was more stable.
    RS and VPS are type of VPS server in Netcup.
     
    Last edited: Oct 11, 2022
  2. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    2:00 PM
    Nginx 1.21.x
    MariaDB 10.x
    That will be problematic as logged in cookie users bypass at CDN cache so speed of TTFB is dependent on your server itself.

    You need to measure your page speed and monitor it too. This is how I do it via Google Analytics > Google Data Studio custom dashboard https://community.centminmod.com/th...nteractive-geo-map-page-speed-insights.22363/

    I wrote a guide on optimizing TTFB with Cloudflare on Cloudflare's official community forum at https://community.cloudflare.com/t/improving-time-to-first-byte-ttfb-with-cloudflare/390367/1 and the bottom section of the guide reads:
    segment 3 is what you'd need to focus on after you have segments 1 and 2 completed. My day job is for paid server optimization consultation for clients where I do all 3 segments for clients. Not cheap those as rates start in 4 figure $$$$ and upwards :)
     
    Last edited: Oct 11, 2022
  3. adamus007p

    adamus007p Member

    357
    18
    18
    Feb 8, 2019
    Ratings:
    +35
    Local Time:
    5:00 AM
    @eva2000 thank you for answer and links :) I am reading it.

    Some of them I have implemented.

    I am looking for some info about
    Page Rules and, CF Workers (i.e. custom/advanced caching) etc.
    CDN cache control, WAF, Firewall

    May you or anyone share with me :)

    I trying to find on forum some examples :)

    Anyway I will be very grateful for any interesting link for reading and learing.

    I have found some nice posts:

    https://community.centminmod.com/th...dpress-and-xenforo-with-newrelic.22047/page-2

    https://community.centminmod.com/threads/how-to-install-redis-server-on-centmin-mod-lemp-stack.4546/


    @eva2000 or anyone :)
    How to cache only not logged users?
    As I understand that cache logged users could be danger? Am i right?
    Or use any ajax to bypass it.
    I am trying to understand it which method can be choosed.
    Send different cookies on nginx side?
    What are possiblites to manage guest and logged users.

    Do you cache also logged users?

    I is safe to cache ecommerce? Or just guesst and not-logged users. Problem with carts etc.

    I am thinking how to bite the problem of cache of dynamic page for ecommerce where you have currencies, languages etc.
    Is it possible to do that?

    Thank you for your times and answers and any advises.
    This forum is a repository of knowledge :)
     
    Last edited: Oct 14, 2022
  4. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    2:00 PM
    Nginx 1.21.x
    MariaDB 10.x
    You generally don't cache logged in users or dynamic requests for such only guests. The links you posted are a good start to the conversation. Best piece of advice is setup a test forum/site and play with various cache/optimisations you come across and see what works or not without impacting your live production site.
     
  5. adamus007p

    adamus007p Member

    357
    18
    18
    Feb 8, 2019
    Ratings:
    +35
    Local Time:
    5:00 AM
    @eva2000 Thank you for answer.
    I am reading all links.

    I just thinking how you or people deal with ecommerce websites.

    Where you e.g 10 languaged and 5 currencies and or some attributs like size, color etc.

    In the internet I did not find nothing regards prestashop. Completly nothing.
    Maybe I will try find something regards Magento or Woocommerce.
    I am thinking maybe to use java to read language or currency or ajax.

    The topic is very interesting and hard. May you share how you or it is possible to deal with it?

    It is a way more complicated then Wordpress and one language.

    I would be vey grateful for any advises.
     
  6. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    2:00 PM
    Nginx 1.21.x
    MariaDB 10.x
    Best advice if your don't know us to hire someone who does.
    With Cloudflare CDN caching you now have Cloudflare Cache Rules https://developers.cloudflare.com/cache/about/cache-rules/ which include limited rule quotas per plan. One rule is for changing the Cloudflare cache key for finer grain control over what Cloudflare CDN Cache stores in cache https://developers.cloudflare.com/cache/about/cache-keys/

    Cloudflare Cache Key use to be a Cloudflare Page Rule option reserved for Cloudflare Enterprise plans but now us available in Cloudflare Cache Rules
     
  7. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:00 PM
    I agree with @eva2000 that you need to focus on "segment 3" that he described above. When I optimized my site, I went from the bottom-up, starting with the clock speed of the CPU to edge-caching with a custom Cloudflare Workers.

    I don't know anything about Prestashop, but my general recommendations for optimizing server response times (TTFB) would be:
    1. Get the absolute fastest clock speed of CPU that you can find.
    2. Run the latest version of PHP that you can (8.0 at least).
    3. Install a server monitoring service with PHP Application Performance Monitor (PHP APM). I use and recommend NewRelic because it is relatively affordable. This will give you visibility into exactly what is consuming time in your app and will give you a baseline for further optimizations. It will help you understand what is causing slow performance and it will allow you to see how the changes you make help or hurt performance over time.
    Good luck!
     
  8. adamus007p

    adamus007p Member

    357
    18
    18
    Feb 8, 2019
    Ratings:
    +35
    Local Time:
    5:00 AM
    @eva2000 @deltahf thank you for all you resposnses.

    This is very helpful info, now I know what I should learn and use.

    May you share with any tutorials regards semgent 3?

    I need to wait for new version of Prestashop where php 8.1 will be supported :)
    Regards CPU I use RS server from Netcup.

    I see that first I need to make some optimization regards Prestashop itself.
    @deltahf may you recommenct any good server with fast CPU?

    Right now I was looking for a server with good network too, but when pages will be cached, CPU is more important, right?

    My current kind of VPS is
    Code (Text):
    16GB RAM
    4CPU
    320 GB SSD



    Thank you thank you guys for everything.
    I am trying to find something in the Internet but there is nothing there (or have no luck to find good resources).
    You are my mentors :)
    I am a begginer but over a years of being here I am learning.
     
  9. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    2:00 PM
    Nginx 1.21.x
    MariaDB 10.x
    It's a big task that is under the umbrella of what is called Linux system administration and for MySQL side, database administration where you need to know how to optimize the server environment itself, web server (Nginx), PHP-FPM, MariaDB MySQL and any something involved in serving your web app i.e. Redis/Memcached etc.

    The first thing is to know how to monitor your server usage info and interpret what that info is telling you. Then you need to know how to change configuration settings for relevant software and re-monitor/re-interpret that info. So basically monitor existing usage/metrics, make a config change and see if it improves the usage/metrics. Rinse and repeat until you have the desired performance and/or until you realise your current server isn't up to the task.

    In the context of Centmin Mod and it's Linux environment some starter threads
    And search this forum and also via Google for users reporting slow performance, high CPU load, or bad performance and read up on those discussions i.e. slow TTFB, slow response times, MySQL slow queries etc. And also test your learnings on a test VPS with a copy of your data rather than on production live server.

    Caching should reduce CPU load on the server that is benefiting from Cache but generally will increase memory usage on the server that is doing the caching. i.e. if you run Centmin Mod Wordpress installer and setup one of the pre-set guest full HTML page caching options, then you'd use more memory on the server if you used say Redis Nginx level guest full HTML page cache. But use more disk space for Cache Enabler/Super Cache plugin based guest full HTML page caching as they're disk mapped cache based (cache is saved to disk).

    However, if you use CDN cache i.e. Cloudflare CDN cache, that should reduce CPU, memory and disk load as the load for caching is offloaded to Cloudflare's server.

    Using both Cloudflare CDN cache + local Centmin Mod caching properly, will give you the best of both worlds. But optimizing segment #3 is more than that, it's whole server system optimization including MySQL database/server optimization.
     
  10. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:00 PM
    That's one reason I'm on a dedicated server with Clouvider, so I have more control over the CPU (I don't think most VPS providers let you tune CPU power profiles, but I could be wrong). I'm not an expert on European hosting, but I think Vultr's "High Frequency Compute" nodes are offering some of the highest VPS clock speeds right now.

    To be frank, I don't think you should count on edge caching to help your specific site too much, if you should even be using it at all. As mentioned, ecommerce pages are highly dynamic and will be changing a lot.

    More importantly, the consequences of stale data getting edge cached on ecommerce pages (price changes, stock levels, etc.) are very high, so you'll need to be absolutely sure your ecommerce software is fully optimized and integrated with Cloudflare or whatever CDN you decide to use to ensure that product pages are purged from the cache when needed.

    And we haven't even touched on other dynamic features like shopping carts and user logins. If a user has an account in your store or items in their cart, they will be some of your most valuable users — and edge caching won't help any of them! So you need to have an extremely fast origin server to handle their requests, too. I recommend focusing all of your efforts on optimizing that first before you get into the more complex topics like edge caching. It is extremely effective in some use cases but it is not a silver bullet and adds a lot of complexity to your site configuration.
     
  11. eva2000

    eva2000 Administrator Staff Member

    49,766
    11,447
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,789
    Local Time:
    2:00 PM
    Nginx 1.21.x
    MariaDB 10.x
    Hit the nail on the head - totally agree :)
     
  12. adamus007p

    adamus007p Member

    357
    18
    18
    Feb 8, 2019
    Ratings:
    +35
    Local Time:
    5:00 AM
    Thank you @deltahf and @eva2000 first of all I am optimizing ecommerce itself.
    There are a lot of mess, spaghetti code, then I will move to PHP 8.1 and check CF.
    I know that eCommerce have dynamic pages, so I was thinking to implement there ajax or something which would read on client side. I need to read more and test it.

    This is for learning and I am wondering if I will achieve it.

    Regards Wordpress is there maybe any tutorial how to cache it on CF side or use workers or full cache page?
    Wordpress would be much easier for learning and testing.