Measuring performance impact on server due to PHP,URI routing
I'm in the process of reworking how the company I work for develops websites. In the old way, there were often several duplicate php files that got called to render a page. e.g page1.php?id=5, page2.php?id=7 where page1.php and page2.php were in most cases simply copies of the same code. This duplication came about as a result of trying to support and maintain compatibil开发者_高级运维ity with legacy frameworks.
The new proposal, is essentially a clean rewrite that routes all calls though the same file using .htaccess, mod_rewrite etc.
I've been asked to show however, the positive or negative impacts this change may have on the server.
Does this method of using only one file to process requests reduce server overhead or does it increase the chances of overloading the server if a high number of persons visited a certain site. Are there any tools that would be able to measure the differences in performance to produce such a report?
For performance impact you can do simple benchmark with 2 tools from the apache community:
- ab, which is good as a base-stress tool
- httperf
- There is also autobench which is built on top of httperf and that will give you some nice graphs after playing some sessions (session that can be obtained from an access.log analysis).
For really simple impact test you can also use simple on-liners like this one (change the real site name and IP, requires netcat):
time printf 'GET / HTTP/1.1\nHost:www.google.com\n\n' | nc -w 10 -q 10 209.85.146.103 80 1>/dev/null
Mod-rewrite won't get a big impact, but you should test it :-) If you have a lot of url to rewrite mod-rewrite has a nice tool : rewriteMap. You will write your url mapping in an external file, and when things will be ok you will even be able to build an hashed version of this map file, so you'll get an ashed index access for each url, this should be lightning fast.
If you put the rules in the main configuration instead of in an .htaccess file you will minimize the performance impact that rewrites will have on the server.
Unless you have some complicated rewrite rules, the overhead that using rewrites will add may not even be noticeable in benchmarks.
精彩评论