{"componentChunkName":"component---src-templates-best-practice-detail-tsx","path":"/best-practice/2021-03-15-wp4","result":{"data":{"currentBlog":{"id":"afd5844f-4acb-5f10-9eb9-bde98bf0c567","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/cb8be2ca0ef4971973d7e3bde82687f6.jpg","authors":["April"],"categories":["best-practice"],"date":"2021-03-15T00:00:00.000Z","title":"Serverless Wordpress 系列建站教程（四）","description":"使用 Serverless Wordpress 部署的网站整体性能高于传统方式","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","WordPress"],"keywords":null,"outdated":null},"wordCount":{"words":162,"sentences":21,"paragraphs":21},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2021-03-15-wp4.md","fields":{"slug":"/best-practice/2021-03-15-wp4/","keywords":["serverless","Serverless","WordPress","网站","请求","服务器","serverless","部署"]},"html":"<p>除了使用成本外，网站性能也是我们在部署个人网站时考虑的另一个重要因素。当用户不再维护服务器层，我们的网站性能又能否可以有效保证？用户对于网站性能的最直观感知就来源于网站速度，当网站的架构 Serverless 化，对网站性能是否有提升？本篇教程将为大家解答这些疑惑。</p>\n<h2 id=\"性能压测\"><a href=\"#%E6%80%A7%E8%83%BD%E5%8E%8B%E6%B5%8B\" aria-label=\"性能压测 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>性能压测</h2>\n<p>我们通过 Serverless WordPress 部署了一个个人网站，同时在一个普通 1 核 1 GB 的服务器里也部署了一个相同的站点，接下来，我们通过 Apache 自带的工具来进行压测。因为测试场景为个人博客，因此设置了 100 并发，1000 次请求，在相同网络环境下测试，测试结果如图：</p>\n<ul>\n<li><strong>传统部署方案压测结果：</strong></li>\n</ul>\n<p><img src=\"https://main.qcloudimg.com/raw/cda317556028c6391a9a7b07ac3e0c07.png\"></p>\n<ul>\n<li><strong>Serverless WordPress 压测结果：</strong></li>\n</ul>\n<p><img src=\"https://main.qcloudimg.com/raw/870c6ccd6529da5b7acbec524764810a.png\"></p>\n<ul>\n<li><strong>结果对比：</strong></li>\n</ul>\n<table>\n<thead>\n<tr>\n<th>部署方案</th>\n<th>80%请求耗时(ms)</th>\n<th>95%请求耗时(ms)</th>\n<th>吞吐率/s</th>\n<th>平均请求耗时(ms)</th>\n<th>平均处理时间(ms)</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>传统方案</td>\n<td>10500</td>\n<td>59776</td>\n<td>6.88</td>\n<td>14527</td>\n<td>145.27</td>\n</tr>\n<tr>\n<td>Serverless WordPress</td>\n<td>3770</td>\n<td>4939</td>\n<td>25.64</td>\n<td>3900</td>\n<td>39.00</td>\n</tr>\n</tbody>\n</table>\n<p>对比可以发现，传统部署方案里，80% 的请求需要在 10s 内完成，而 Serverless WordPress 95% 的请求都可以在 5s 内完成，同时吞吐率、用户平均请求等待时间、服务器平均请求处理时间三个重点指标，Serverless WordPress 的表现不仅不逊色，甚至更为优异。因此，开发者可以尽情拥抱 Serverless 生态，所有的性能问题都交给 Serverless 架构底层帮您解决。</p>\n<h2 id=\"性能提升\"><a href=\"#%E6%80%A7%E8%83%BD%E6%8F%90%E5%8D%87\" aria-label=\"性能提升 permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>性能提升</h2>\n<p>当然，WordPress 本身也提供了多种方案帮助您持续提升网站性能，您可以采用以下几个方案，进一步提升您的网站速度：</p>\n<ul>\n<li>\n<p>有效使用缓存</p>\n<p>作为一个动态网站，每个请求 WordPress 都会将所有内容重新进行加载并生成，这一步往往耗时很大，因此，WordPress 市场有许多优秀的缓存插件，比如 <strong>WP Super Cache</strong>、<strong>WP Rocket</strong>、<strong>W3 Total Cache</strong> 等等，它们会生成网站的静态HTML页面，并将其保存在服务器上，每次请求时直接访问，无需重复计算，有效减轻服务器压力。</p>\n</li>\n<li>\n<p>合理选择主题插件</p>\n<p>有些开发者往往会给自己的网站安装大量插件和主题，这些同样会对页面的请求速度产生影响，建议您简化网站的插件库，尽量使用轻量的框架主题，这些对于网站速度提升均有一定帮助。</p>\n</li>\n<li>\n<p>动静分离，使用 CDN</p>\n<p>一个 WordPress 站点往往分为动态资源和静态资源两个部分，网站的 CSS，JS 文件以及一些常用的图片文件，往往不会做更改，因此将静态资源分离，并使用 CDN 加速，将大大降低服务器的压力，这也服务器只需要获取动态资源，所有的静态资源可以从 CDN 直接获取。Serverless WordPress 现在也已经支持 CDN 加速能力，后续将会写一篇教程指导大家如何为 Serverless WordPress 配置 CDN。</p>\n</li>\n</ul>\n<p>新用户第一次部署 WordPress 应用，即可获得 <strong>30 元 TDSQL-C，5 元 CFS 文件存储</strong>代金券，欢迎登录控制台免费体验！</p>\n<p>部署链接：<a href=\"https://console.cloud.tencent.com/sls/create?t=wordpress&#x26;from=wx\">https://console.cloud.tencent.com/sls/create?t=wordpress&#x26;from=wx</a></p>\n<hr>\n<blockquote>\n<p><strong>传送门：</strong></p>\n<ul>\n<li>GitHub: <a href=\"https://github.com/serverless/serverless/blob/master/README_CN.md\">github.com/serverless</a></li>\n<li>官网：<a href=\"https://serverless.com/\">serverless.com</a></li>\n</ul>\n</blockquote>\n<p>欢迎访问：<a href=\"https://serverlesscloud.cn/\">Serverless 中文网</a>，您可以在 <a href=\"https://serverlesscloud.cn/best-practice\">最佳实践</a> 里体验更多关于 Serverless 应用的开发！</p>","tableOfContents":"<ul>\n<li><a href=\"/best-practice/2021-03-15-wp4/#%E6%80%A7%E8%83%BD%E5%8E%8B%E6%B5%8B\">性能压测</a></li>\n<li><a href=\"/best-practice/2021-03-15-wp4/#%E6%80%A7%E8%83%BD%E6%8F%90%E5%8D%87\">性能提升</a></li>\n</ul>"},"previousBlog":{"id":"286a22c7-8662-5105-a6fe-de6fb25bd445","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/984bf4cf35beba9c5f1233d1d13cfd94.png","authors":["陈涛"],"categories":["best-practice"],"date":"2021-03-17T00:00:00.000Z","title":"如何使用 Serverless + CLB 快速部署 Web 服务？","description":"更低成本、免运维，为开发者平滑迁移应用上云提供参考","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","CLB"],"keywords":null,"outdated":null},"wordCount":{"words":126,"sentences":29,"paragraphs":28},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2021-03-17-clb.md","fields":{"slug":"/best-practice/2021-03-17-clb/","keywords":["serverless","云函数","width"]}},"nextBlog":{"id":"e3404db5-7511-5697-98ba-f40b0ad677f6","frontmatter":{"thumbnail":"https://main.qcloudimg.com/raw/cb8be2ca0ef4971973d7e3bde82687f6.jpg","authors":["April"],"categories":["best-practice"],"date":"2021-03-09T00:00:00.000Z","title":"Serverless Wordpress 系列建站教程（三）","description":"使用 Serverless 建站是如何计费的","authorslink":null,"translators":null,"translatorslink":null,"tags":["Serverless","WordPress"],"keywords":null,"outdated":null},"wordCount":{"words":260,"sentences":57,"paragraphs":57},"fileAbsolutePath":"/opt/build/repo/content/best-practice/2021-03-09-wp3.md","fields":{"slug":"/best-practice/2021-03-09-wp3/","keywords":["serverless","云函数","Serverless","计费","WordPress","费用","tencent"]}}},"pageContext":{"isCreatedByStatefulCreatePages":false,"blogId":"afd5844f-4acb-5f10-9eb9-bde98bf0c567","previousBlogId":"286a22c7-8662-5105-a6fe-de6fb25bd445","nextBlogId":"e3404db5-7511-5697-98ba-f40b0ad677f6"}}}