简体   繁体   English

PHP性能指标

[英]PHP Performance Metrics

I am currently developing a PHP MVC Framework for a personal project. 我目前正在为个人项目开发PHP MVC框架。 While I am developing the framework I am interested to see any notable performance by implementing different techniques for optimization. 在我开发框架的同时,我有兴趣通过实现不同的优化技术来看到任何显着的性能。 I have implemented a crude BenchMark class that logs mircotime. 我已经实现了一个粗略的BenchMark类来记录mircotime。

The problem is I have no frame of reference for execution times. 问题是我没有执行时间的参考框架。 I am very near the beginnig of this project with a database connection and a few queries but no output (bar some debugging text and BenchMark log). 我非常接近这个项目的开始,有一个数据库连接和一些查询,但没有输出(禁止一些调试文本和BenchMark日志)。 I have a current execution time of 0.01917 seconds . 我的当前执行时间为0.01917 seconds

I was expecting this to be lower but as I said before I have no frame of reference. 我期待这个更低,但正如我之前所说,我没有参考框架。 I appreciate there are many variables to take into account when juding performance but I am hoping to find some sort of metric to 我很欣赏在演出时要考虑很多变量,但我希望找到某种指标
a) techniques to measure performance for example requests per second and a)测量性能的技术,例如每秒的请求和
b) compare results for example; b)例如比较结果; how a "moderately" sized PHP application on a "standard" webserver will perform. “标准”Web服务器上的“适度”大小的PHP应用程序将如何执行。 I appreciate "moderately" and "standard" are very subjective words so perhaps a table of known execution times for a particular application (eg StackOverFlow's executing time). 我理解“适度”和“标准”是非常主观的词,因此可能是特定应用程序的已知执行时间表(例如StackOverFlow的执行时间)。

What are other techniques of measuring performance are there other than execution time? 除了执行时间之外,还有哪些其他测量性能的技术?

When looking at MVC Framework Performance Comparisom it talks about Requests Per Second (RPS). 在查看MVC框架性能比较时,它讨论了每秒请求数(RPS)。 How is this calculated? 这是怎么计算的? I am guessing with my current execution time of 0.01917 seconds can handle 52 RPS (= 1 / 0.01917 ) . 我猜测我当前的执行时间0.01917 seconds可以处理52 RPS (= 1 / 0.01917 ) This seems to be significantly lower than that quoted on the graph especially when you consider my current limited funcitonality. 这似乎明显低于图表上引用的内容,尤其是当您考虑我目前有限的功能时。

To benchmark a certain page, use ab . 要对特定页面进行基准测试,请使用ab To benchmark a load of pages on the server, try siege . 要对服务器上的页面加载进行基准测试,请尝试围攻

However... both of those are still mostly artificial tests. 然而......这两者仍然主要是人工测试。 I personally add some extra logs too. 我个人也添加了一些额外的日志。

  • Page load time in the webserver (or proxy, whatever) 网页服务器(或代理,无论如何)中的页面加载时间
  • Slow query logging in the database 数据库中的慢查询日志记录
  • Query count logging per page too if possible, that way you'll know how heavy your pages are ;) 如果可能,也会在每页查询计数记录,这样您就可以知道页面有多重;)

You can use xdebug to profile your code. 您可以使用xdebug来分析您的代码。 But you are optimizing way too early in the development process. 但是你在开发过程中过早地优化了方法。 Just the act of calling microtime is going to slow things down since it has to make a call out to the system (outside the PHP engine). 只是调用microtime的行为会减慢速度,因为它必须调用系统(在PHP引擎之外)。 Every include, object creation, connection to another resource (ie database) is going to add a lot of overhead, relatively speaking. 相对而言,每个包含,对象创建,与另一个资源(即数据库)的连接将增加大量开销。

If you design your system to be very cache friendly, then you don't have to execute code. 如果您将系统设计为非常缓存友好,那么您不必执行代码。 For example, WordPress is very slow. 例如,WordPress非常慢。 About 15 pages/sec on a decent web server. 在体面的Web服务器上大约15页/秒。 It does a lot of includes and runs a lot of code. 它做了很多包括并运行了很多代码。 But add the SuperCache plugin and performance increases 10x. 但是添加SuperCache插件并且性能提高了10倍。 It works by creating a cache file and using some Apache rules so PHP doesn't have to be run at all. 它的工作原理是创建一个缓存文件并使用一些Apache规则,因此PHP根本不必运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM