{"id":1649,"date":"2021-12-12T14:50:34","date_gmt":"2021-12-12T22:50:34","guid":{"rendered":"https:\/\/fighternan.com\/?p=1649"},"modified":"2022-10-02T23:07:55","modified_gmt":"2022-10-03T06:07:55","slug":"improve-wordpress-performance","status":"publish","type":"post","link":"https:\/\/nanzhou.cc\/index.php\/2021\/12\/12\/improve-wordpress-performance\/","title":{"rendered":"Improve WordPress Performance"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This post summarized my recent attempt to improve the performance of my website. This post will be updated from time to time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Recently, I got a Black Friday deal at my previous server provider. I chose their new plan and migrated my website from Germany to the United States.  I&#8217;ve noticed that the latency increased quite a lot. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> I used an <a href=\"https:\/\/gtmetrix.com\/reports\/fighternan.com\/DUCqEACE\/\" data-type=\"URL\" data-id=\"https:\/\/gtmetrix.com\/reports\/fighternan.com\/DUCqEACE\/\">online tool<\/a> to test the performance. Below is the snapshot of the result.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"754\" src=\"https:\/\/fighternan.com\/wp-content\/uploads\/2021\/12\/1639347195291-1024x754.jpg\" alt=\"\" class=\"wp-image-1650\" srcset=\"https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/1639347195291-1024x754.jpg 1024w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/1639347195291-300x221.jpg 300w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/1639347195291-768x565.jpg 768w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/1639347195291-1536x1131.jpg 1536w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/1639347195291-2048x1508.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Obviously the bottleneck is the TTFB (Time to First Byte). 5 seconds are ridiculous given that it didn&#8217;t take too much time to reach the host.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><meta charset=\"utf-8\">fighternan-macbookpro% ping fighternan.com\nPING fighternan.com (66.94.114.210): 56 data bytes\n64 bytes from 66.94.114.210: icmp_seq=0 ttl=49 time=32.413 ms\n64 bytes from 66.94.114.210: icmp_seq=1 ttl=49 time=33.306 ms\n64 bytes from 66.94.114.210: icmp_seq=2 ttl=49 time=32.246 ms\n64 bytes from 66.94.114.210: icmp_seq=3 ttl=49 time=38.215 ms<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To dive deeper into why it took so much time, I installed a plugin called <a href=\"https:\/\/wordpress.org\/plugins\/query-monitor\/\">Query Monitor<\/a>. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"213\" src=\"https:\/\/fighternan.com\/wp-content\/uploads\/2021\/12\/image-1024x213.png\" alt=\"\" class=\"wp-image-1651\" srcset=\"https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1024x213.png 1024w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-300x62.png 300w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-768x159.png 768w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1536x319.png 1536w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-2048x425.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">To load the main page, it took about 3 seconds totally to query the database. My database is also based in US and I&#8217;ve checked the Memory and CPU usage. Both looked fine. Database might not be the bottleneck. My next guess is that the network latency is the thing we need to improve: we should avoid query database as much as we can.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I searched a bit in the WordPress plugin market and found that <a href=\"https:\/\/wordpress.org\/plugins\/w3-total-cache\/\">this useful tool<\/a>. It provides a very important cache in our case: page caching. This cache in my understanding basically spins up a background thread to crawl certain pages and stores results in some storage engine (e.g. disk, Memcache, Redis). It aims to speed up <meta charset=\"utf-8\">TTFB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I then got the following performance result.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"738\" src=\"https:\/\/fighternan.com\/wp-content\/uploads\/2021\/12\/image-1-1024x738.png\" alt=\"\" class=\"wp-image-1652\" srcset=\"https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1-1024x738.png 1024w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1-300x216.png 300w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1-768x553.png 768w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1-1536x1106.png 1536w, https:\/\/nanzhou.cc\/wp-content\/uploads\/2021\/12\/image-1-2048x1475.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>My manual tests on several other pages also worked well. <\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post summarized my recent attempt to improve the performance of my website. This post will be updated from time to time. Recently, I got a Black Friday deal at my previous server provider. I chose their new plan and migrated my website from Germany to the United States. I&#8217;ve noticed that the latency increased&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,71],"tags":[],"class_list":["post-1649","post","type-post","status-publish","format-standard","hentry","category-web","category-wordpress"],"_links":{"self":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/comments?post=1649"}],"version-history":[{"count":2,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1649\/revisions"}],"predecessor-version":[{"id":1675,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1649\/revisions\/1675"}],"wp:attachment":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/media?parent=1649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/categories?post=1649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/tags?post=1649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}