Author |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Sun 01 Mar '15 21:00 Post subject: Reducing TTFB (Linux LAMP server) |
|
|
I've just switched my Apache and PHP config over to linux(ubuntu 14.10).
Apache 2.4.12 is using the mpm-event worker and PHP 5.6 is running in FastCGI/fpm mode.
I'm running MariaDB 10.0.17
I'd like to reduce the time to first byte even more, its currently 80 ms for static files and 110ms for PHP generated pages.
1. 80 ms seems like a lot, since the ping to the server is <15ms
How can I reduce this?
Are there some tweaks for the Linux networking stack or Apache that I can apply?
I'm also using SSL, I remember it could be tweaked to improve its performance but I don't remember how..
I currently enabled the following in my main apache config:
Code: | ServerSignature Off
ServerTokens Prod
TraceEnable off
EnableMMAP on
EnableSendfile on
UseCanonicalName On
|
2. Is there a mod_spdy for Apache 2.4? what about http 2.0?
3. Can I tell PHP to make use of unix sockets to connect to the database server? (I heard unix sockets is faster)
4. I've installed memcached for PHP, can I also use this for Apache? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 02 Mar '15 15:39 Post subject: |
|
|
Are you running event or worker mpm?
What are your mpm settings?
I use
EnableMMAP off and EnableSendfile Off
Also you should set HostnameLookups Off to disable DNS lookup
To improve SSL Handling (modify the paths for your needs)
Code: |
SSLUseStapling on
SSLSessionCache shmcb:/opt/apache2/logs/ssl_gcache_data(512000)
SSLStaplingCache shmcb:/opt/apache2/logs/ssl_stapling_data(512000)
SSLOptions +StrictRequire +StdEnvVars -ExportCertData
|
Yepp the socket connection from PHP to MySQL is faster than the TCP connection. You just have to use the socket path in your connection. Instead if the hostname you use :/path/to/socket
PHP can run with memcached with your distro offers the PHP memcache extension.
If I use linux I use debian and there I can use dotdeb to use PHP 5.6 with OPCache which increases the speed. |
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Tue 03 Mar '15 17:44 Post subject: |
|
|
Thanks James
I'm using the event mpm, with the default config.
When I use: /var/run/mysqld/mysqld.sock instead of 127.0.0.1 in Joomla or SMF it can't connect to the database..
I already had hostnamelookups off,
I'll test if there is a performance difference when changing EnableMMAP off and EnableSendfile Off, on should be faster on Linux.. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Tue 03 Mar '15 18:20 Post subject: |
|
|
You can also play a bit with your mpm settings
I had to increase some of the values for my needs.
Code: |
# event MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxConnectionsPerChild: maximum number of connections a server process serves
# before terminating
<IfModule mpm_event_module>
StartServers 3
MaxClients 320
MinSpareThreads 40
MaxSpareThreads 80
ThreadsPerChild 20
MaxConnectionsPerChild 0
</IfModule>
|
|
|
Back to top |
|
gijs
Joined: 27 Apr 2012 Posts: 189 Location: The Netherlands
|
Posted: Tue 03 Mar '15 19:52 Post subject: |
|
|
I've ran the tests and the performance difference is inconclusive between having EnableSendfile on or off.
EnableMMAP on reduces the ttfb slightly.
I've edited my worker settings, but I doubt it makes a difference since my server isn't under heavy load. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Mon 16 Mar '15 12:15 Post subject: |
|
|
In this cae I would try to benchmark it with ab.exe to a static html file (several runs) and then to a PHP page. |
|
Back to top |
|