Sunday, January 27, 2013

php performance Profiling

ProfilingSo you’ve done all the caching and query optimizations, and removed all
the system bottlenecks, but your code is still running too slow. Now you have to
face the music and admit that, actually, your code isn’t perfect and could be im-
226 PHP Master: Write Cutting-edge Code
proved. But you already did the best you could … so, now what? This is where
profiling comes in.
is the act of taking accurate time and/or memory measurements for every action
your code performs. This is then explored to determine where the bottlenecks lie.


There are two tools for profiling that are commonly used:

1. Xdebug
2. XHProf -XHGui

php performance caching

Caching


1. APC
2. Memcache

php performace with memecache

Another setting that you can tweak for optimization is to use a different storage
mechanism for session data; in this case memcached. Memcached is a memorybased,
cluster-friendly key-value store. If you enable the memcache extension
(ext/memcache), you’ll be able to automatically use memcached for session storage
instead of the disk:


Install
$ pecl install memcache # Install ext/memcache
$ memcached –d –m 128 # Start memcached

Settings

session.save_handler = "memcache"
session.save_path = "tcp://localhost:11211"Table 6.1. Performance Figures with and without Memcached

StorageType               AverageResponse  MinimumResponse Maximum Response  Requests per Second
File-based                    836                             98                       7106                        23
MySQL-based             798                            103                      1848                          24
Memcached-based        771                            86                        1473                        25



Memcached is a networked daemon that can easily be spread across multiple servers.
In this case, multiple web servers can use it as a central store for their sessions. This
makes load balancing much easier; all sessions can easily be accessed from all web
servers in a cluster, without the overhead of a central RDBMS (relational database
management system).
As the number of sessions grows, memcached will scale far better.

Php performance code caching

The first item we’re going to cover is opcode caches. You’ve probably heard since
your earliest days as a PHP developer that PHP is a scripting language, an interpreted language, that no compiling is required … well, this isn’t exactly true. Stick with
us here.

So, how do you install this magic? It’s simple:

$ pecl install apc
extension=apc.so

Now Again compare with ab benchmarking technique
Now see difference and you will be most happiest person of world.

PHP Performace Jmeter

JMeter is another Apache project with a GUI, and more capability.With JMeter, you
create a test plan, add thread groups (for example, X number of threads performing
N number of requests each), add samplers (such as performing an HTTP request),
specify their configuration, add other options like a cookie handler, and add
listeners to handle the results.

php performance Apache benchmark

Apache benchmark


ApacheBench is super simple and typically included with your Apache install, or
as part of the Apache development package—the binary is called simply ab. To use
ab, just specify the total number of requests (-n), and the number of simultaneous
threads (-c), and let it go to work. For example, here we are using –n 10000 –c 40
to create 40 simultaneous threads to perform 1,000 requests:


$ ab -n 10000 -c 40 http://www.test.com/

Connect: 1 6 4.8 4 30
Processing: 62 233 49.6 229 708
Waiting: 62 231 50.1 227 705
Total: 63 239 49.5 235 714

The Connection Times section is very interesting, as it comprises four different
numbers:
Connection: how long it takes the web server to open a connection
Processing: how long the request takes, from the time of connection to the end
of the request
Waiting: how long it takes Apache to process the request and send the full
response
Total: how long the request takes from start to finish