Zend Server 7 was released last week which includes Z-ray, a performance analysis tool. (Think X-ray vision.) I have done my fair share of performance analysis over the years in C/C++ and Java, so was curious to see how good the tools around are for PHP. So here are my experiences after a few days of kicking the tires.
Zend Server 7 has a few editions with 30 day evaluation periods. I grabbed the Enterprise version for Windows and put it on my laptop. I don’t remember the exact installation sequence, but I made sure I enabled Z-ray by default. Configuration all up was pretty simple.
(Later, I tried to turn the server off. Since I was on Windows, I went to Control Panel and found Services. Sure enough, there was Apache2.2-Zend plus 5 other services starting with “Zend” at the bottom of the list. Fairly easy to shut down.)
I had not used Zend Server before in earnest, so after installation I started looking to work out the easiest way to get my existing local source tree working with Zend Server. There was lots of talk about how to create deployment packages, but I was hoping for faster edit/test cycles than having to build a package and deploy it each time. I noticed something about “defining applications” which talked about adding an already deployed application. I remembered also someone saying how easy it was to achieve, so I persisted and finally found the page Deploying Code with Zend Server. For Windows, there is an Apache2\htdocs directory under which you can drop your applications directly – no need to package and deploy. (Yay!)
Rather than copy my code, I cheated further by creating a symlink using MKLINK /D. My local source code then appeared under the Zend Apache web server directory and it all started working. (For Linux, you may need to change some configuration file to allow following of symbolic links – not sure.) So I did not have to mess with my normal development practices to get it going.
Next I pointed my web browser at my application and watched what happened. At the bottom of the page the Z-ray bar appeared. I immediately
went to read the documentation started clicking buttons to see what would happen. (OK, truth be told I had been given a demo beforehand so I had a pretty good idea what was going to happen.)
- First button showed a summary of HTTP requests, elapse time, number of database queries for the page. I think this will be more important with pages doing AJAX calls.
- Second button was a pause tracking button.
- Third button was a ‘clear’ button – wiped recorded results.
- Fourth showed a summary of how much time in PHP, Database, IO, and network. Also showed peak memory usage.
- Fifth had a “slow page” and “lots of memory” warning. I assume the admin interface would let me change the alerts.
- Sixth was errors and warnings. The demo I saw showed uncaught exceptions or similar here.
- Seventh button is where it starts getting really interesting. It shows all the database queries issued for that page load with elapse time per query. Very nice! I mean this information is available in logs, but doing a page load and seeing it right there on the page – nice!
- Eighth button shows the PHP profile for the last page load. Shows inclusive and exclusive time (function call including duration of child function calls, and without child function calls), number of calls, etc. You could exclude groups of functions you were not interested in.
- Nineth button shows the $_ variables (like $_SESSION and $_COOKIE). A cute feature is to be able to show only values that were changed by the page request.
I spent most of my time looking at the function profile. The database query list is something I can imagine getting to next, but just knowing how many database accesses were performed to bring up a single page was rather sobering. (Also impressive – MySQL is pretty fast!) I did notice a few of the figures did not seem to add up. When I asked the folks at Zend it was explained that some of the numbers include start up times for the PHP interpreter, some figures included the performance collecting overheads and others didn’t, etc. Not a big deal.
So is Z-ray useful? The thing I really like is how easy it is to get a performance profile. I can change code in my IDE, save it, and reload the web page in a browser to get a new results. The elapse time figures did jump around a bit between runs without code change, but it definitely accelerated the experimentation cycle. I think the main value will be because it is so easy to see your performance profile (and queries and memory usage) you will look at it more often. If you care about performance, definitely worth checking out the free trial period. It would not replace having a formal load and performance test framework, but kinda cool for ad-hoc experimentation.
Did I identify performance problems in the code base I was playing with using the tool? Yes. Known problems in my case, but it made it really clear how significant the problem was, and importantly how effective different quick experiments were to solve the problem.
Oh, if you want some screen shots or demos, try here.
Disclaimer: These opinions are my own and not that of my employer.