logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Reducing TTFB (Linux LAMP server)
Author
gijs



Joined: 27 Apr 2012
Posts: 189
Location: The Netherlands

PostPosted: Sun 01 Mar '15 21:00    Post subject: Reducing TTFB (Linux LAMP server) Reply with quote

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: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 02 Mar '15 15:39    Post subject: Reply with quote

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

PostPosted: Tue 03 Mar '15 17:44    Post subject: Reply with quote

Thanks James Smile
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: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 03 Mar '15 18:20    Post subject: Reply with quote

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

PostPosted: Tue 03 Mar '15 19:52    Post subject: Reply with quote

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: 7371
Location: Germany, Next to Hamburg

PostPosted: Mon 16 Mar '15 12:15    Post subject: Reply with quote

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


Reply to topic   Topic: Reducing TTFB (Linux LAMP server) View previous topic :: View next topic
Post new topic   Forum Index -> Apache