LxCenter HyperVM & Kloxo Support

Forum



Members   Search      Help    Register    Login    Home
Home » LxCenter » Contributed HOWTOs » Apache httpd config to compete with nginx and lighttpd
Apache httpd config to compete with nginx and lighttpd [message #94387] Thu, 19 January 2012 21:42 Go to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Here is the start of a configuration that will pass the 50 user test from loadimpact.com with no sweat with a heavy php application like Drupal 7. This is from a CentOS base install and will not work for SSL or VirtualHosts as is. I will add that later. I want the community to try this out and let me know what they think in general.

The idea is that httpd-light acts as lighttpd or nginx and servers only static content. It directs php requests to the httpd config.

Here it is!:

#Install the LAMP components
yum -y install httpd mysql mysql-server php53 php53-gd php53-pdo php53-mbstring php53-xml php53-mysql

#Create init.d script for httpd-light
cp /etc/init.d/httpd /etc/init.d/httpd-light
sed -i 's/httpd Startup/httpd-light Startup/g' /etc/init.d/httpd-light
sed -i 's/processname: httpd/processname: httpd-light/g' /etc/init.d/httpd-light
sed -i 's,/etc/httpd/conf/httpd.conf,/etc/httpd-light/conf/httpd.co nf,g' /etc/init.d/httpd-light
sed -i 's,/etc/sysconfig/httpd,/etc/sysconfig/httpd-light,g' /etc/init.d/httpd-light
sed -i 's,/var/run/httpd.pid,/var/run/httpd-light.pid,g' /etc/init.d/httpd-light
sed -i 's,prog=httpd,prog=httpd-light,g' /etc/init.d/httpd-light
sed -i 's,/var/lock/subsys/httpd,/var/lock/subsys/httpd-light,g' /etc/init.d/httpd-light
sed -i '/STOP_TIMEOUT=/ a\
OPTIONS="-f /etc/httpd-light/conf/httpd.conf"' /etc/init.d/httpd-light

#Create httpd-light configuration directory and configure httpd-light
cp -r /etc/httpd/ /etc/httpd-light
sed -i 's,ServerRoot "/etc/httpd",ServerRoot "/etc/httpd-light",g' /etc/httpd-light/conf/httpd.conf
sed -i 's,PidFile run/httpd.pid,PidFile run/httpd-light.pid,g' /etc/httpd-light/conf/httpd.conf

#Create new file /etc/httpd-light/conf.d/reverseproxy.conf
echo LoadModule proxy_module modules/mod_proxy.so> /etc/httpd-light/conf.d/reverseproxy.conf
echo ProxyPreserveHost on>> /etc/httpd-light/conf.d/reverseproxy.conf
echo ProxyPassReverse / http://127.0.0.1:8080/>> /etc/httpd-light/conf.d/reverseproxy.conf
echo RewriteEngine on>> /etc/httpd-light/conf.d/reverseproxy.conf
echo RewriteCond %{REQUEST_URI} .*\\.\(php\)$>> /etc/httpd-light/conf.d/reverseproxy.conf
echo RewriteRule ^/\(.*\) http://127.0.0.1:8080/\$1 [P]>> /etc/httpd-light/conf.d/reverseproxy.conf

#No need for php on the httpd-light
rm -f /etc/httpd-light/conf.d/php.conf

#Configure httpd config
sed -i 's/Listen 80/Listen 127.0.0.1:8080/g' /etc/httpd/conf/httpd.conf

#Configure httpd for 10 max clients (uses about X MB)
sed -i 's/ServerLimit 256/ServerLimit 10/g' /etc/httpd/conf/httpd.conf
sed -i 's/MaxClients 256/MaxClients 10/g' /etc/httpd/conf/httpd.conf

#invalidate the worker config in the main httpd.conf for httpd-light
sed -i 's/<IfModule worker.c>/<IfModule worker-old.c>/g' /etc/httpd-light/conf/httpd.conf

#Configure httpd-light for worker max clients (uses about X MB)
sed 's,#HTTPD=/usr/sbin/httpd.worker,HTTPD=/usr/sbin/httpd.worke r,g' /etc/sysconfig/httpd > /etc/sysconfig/httpd-light

echo "<IfModule worker.c>
ThreadLimit 1024
StartServers 2
MaxClients 2048
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 1024
MaxRequestsPerChild 0
</IfModule>"> /etc/httpd-light/conf.d/worker.conf

chkconfig httpd on
chkconfig httpd-light on
chkconfig mysqld on

service httpd start
service httpd-light start
service mysqld start


https://www.mercuryvps.com
HyperVM Xen VPS hosting

[Updated on: Wed, 25 January 2012 21:06]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94389 is a reply to message #94387] Thu, 19 January 2012 22:59 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Ooh already a nice little addition to this. I will be changing the httpd-light to worker. In my intial testing I couldn't get worker to work. I just tried it again and success. I will post a change once I rebuild the server and run through it all again.

https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94394 is a reply to message #94389] Fri, 20 January 2012 06:02 Go to previous messageGo to next message
Spacedust is currently offline Spacedust  Poland
Messages: 1233
Registered: October 2007
Location: Poland
Senior Master
This is interesting. I'm waiting for version with support for virtual hosts.
Re: Apache httpd config to compete with nginx and lighttpd [message #94406 is a reply to message #94394] Fri, 20 January 2012 16:39 Go to previous messageGo to next message
dkstiler is currently offline dkstiler  Greece
Messages: 16
Registered: October 2011
Location: Greece
Member
it seems a nice solution when i will have some time i will try to test it me 2 with 32bit and 64bit architectures ... and i will post here the results Smile
Re: Apache httpd config to compete with nginx and lighttpd [message #94482 is a reply to message #94406] Sun, 22 January 2012 20:19 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Added
DirectoryIndex index.php> /etc/httpd-light/conf.d/reverseproxy.conf


https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94483 is a reply to message #94482] Sun, 22 January 2012 20:40 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Oops! I have the max clients on these configs incorrect. They should be swapped. Correcting the top post now.

https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94571 is a reply to message #94483] Wed, 25 January 2012 21:09 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Updated to worker. I still need to run through it a few times.

Neat things I will add.

Multiple php pools, for instance - httpd-php-free, httpd-php-premium, httpd-php-exclusive1.

Basically this config should make it possible to have some virtual hosts use the free, others use premium, and even have exclusive pools. Also I want to add a php6 and maybe php5X choices to the mix.

Next thing I post should be the SSL and then the virtual hosts. It may take me a bit to get that working well.


https://www.mercuryvps.com
HyperVM Xen VPS hosting

[Updated on: Wed, 25 January 2012 21:10]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94579 is a reply to message #94571] Thu, 26 January 2012 09:19 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
BTW, I found out that the php53 package is not recommended by even CentOS it seems. Don't take this as me suggesting that it should be used. It just makes it easier for me to do the testing of this config with Drupal 7.

https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94583 is a reply to message #94387] Thu, 26 January 2012 10:08 Go to previous messageGo to next message
Spacedust is currently offline Spacedust  France
Messages: 1233
Registered: October 2007
Location: Poland
Senior Master
Will this be a part of Kloxo when finished ?
Re: Apache httpd config to compete with nginx and lighttpd [message #94584 is a reply to message #94583] Thu, 26 January 2012 10:15 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
I want to have this thoroughly working as standalone first. I then MIGHT add it as a hidden driver, where a file flag must be set to use. This will allow great testing, and make sure that a person does not just choose it without having to know that it is still in testing.

So please test out this config as I go along to make sure it is sane and will do what I want. This is set up to work very well on 512 MB. If you set up on a 1GB,you should be able to double the httpd-light MaxClients and also double the httpd MaxClients.

Any thoughts on the separate php pools?


https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94642 is a reply to message #94584] Sat, 28 January 2012 21:00 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
This is purely for show and for people to have a little peak at what this configuration will be able to do. This can currently run on 256 MB of memory but could go over just a little bit, so have some swap if you test some heavy php. Also you could manually lower the MaxClients for the httpd prefork from 10 to 5. The httpd-light will hold over 2000 concurrent connections:)

How to test...
Install Kloxo as normal.
Download this file:
https://raw.github.com/shazarlx/kloxo/2609820317b6d4fa89945c 6b2bc642b284f78790/kloxo/httpdocs/lib/domain/web/driver/web_ _httpdlightlib.php

Copy it to /usr/local/lxlabs/kloxo/httpdocs/lib/domain/web/driver/
Backup the old web__apachelib.php and rename web__httpdlightlib.php to web__apachelib.php

Add a domain under admin.
Manually restart the httpd and httpd-light services as I haven't added that part yet.
Add some static files and some php files and test it.
Stop httpd and you will notice php files will fail.
Stop httpd-light and all requests will fail.

I've not tested much else and I know not much else will work.

This is very early and I plan to make a lot of changes in how the install and configuration goes. The way I did this rides on the way the current driver is written.



https://www.mercuryvps.com
HyperVM Xen VPS hosting

[Updated on: Sat, 28 January 2012 21:02]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94658 is a reply to message #94642] Sun, 29 January 2012 11:22 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
OOps missed something. After putting the file in place, you want to switch to lighttpd and then back to apache. This wouldn't be needed once this is fully complete of course.

https://www.mercuryvps.com
HyperVM Xen VPS hosting

[Updated on: Mon, 30 January 2012 09:42]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94704 is a reply to message #94658] Tue, 31 January 2012 08:31 Go to previous messageGo to next message
Spacedust is currently offline Spacedust  Poland
Messages: 1233
Registered: October 2007
Location: Poland
Senior Master
I don't trust Apache anymore. Any config will be too slow. See how G-WAN performs: http://gwan.com/benchmark

Does this support virtual hosts now ?

Please post some benchmark on some good machine (not VPS).

[Updated on: Tue, 31 January 2012 08:34]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94707 is a reply to message #94704] Tue, 31 January 2012 09:09 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Spacedust - from what you've shown in other threads, you don't know how to configure Apache. Of course if you have mod_php with MaxClients set to 256 you will crash your system with almost any amount of memory. Each mod_php apache process takes up at least 30 MB. Each process supports a single concurrent connection/request. This configuration that I have presented does the same thing that lighttpd and nginx does but is pure apache. Apache is THE webserver of choice bar none.

If you check out that file that I linked to you will be able to add a domain from Kloxo and a virtual host will be made. I've already figured out a better way to consolidate the configuration though. I would like you to test it.

Benchmarks with ab are completely useless. I have been using loadimpact.com against a Drupal 7 install. It is very php intensive and comes default with a ton of objects that need to load on every page. With 256 MB of memory it passes the 50 concurrent users without a problem. The default apache config would crash your system almost instantly if you kept it at 256 MaxClients. If you tweaked it to not crash (MaxClients 5), the 10 clients part of the test would be slow and you would most likely not get passed the 20 mark.

Regarding other webservers, I have absolutely no interest in anything other than apache.

Please feel free to use this as a chance to run the benchmarks. If you use the ab application to do it, it proves absolutely nothing as it only does the single page you request and not the linked objects and also if you use it locally, you have no Internet latency. ab ends up being more CPU intensive when run locally and shows absolutely nothing about real world performance. I use ab to max out my connections to review the full memory usage though.


https://www.mercuryvps.com
HyperVM Xen VPS hosting

[Updated on: Tue, 31 January 2012 09:12]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94722 is a reply to message #94707] Tue, 31 January 2012 18:05 Go to previous messageGo to next message
Spacedust is currently offline Spacedust  Poland
Messages: 1233
Registered: October 2007
Location: Poland
Senior Master
I will test this on my own software and compare this with my current lighttpd configuration.

The problem I was facing on my production server when I changed lighttpd to Apache was incredibly high I/O load and total server load went from 20.00 to almost 80.00.

What do you think about: http://trafficserver.apache.org/ ?

[Updated on: Tue, 31 January 2012 18:13]

Report message to a moderator

Re: Apache httpd config to compete with nginx and lighttpd [message #94723 is a reply to message #94722] Tue, 31 January 2012 18:11 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
The default is 256 MaxClients at 30 MB each. This leads to a possible memory usage of 8 GB minimum. 30 MB is a minimum I go by and have seen it go much much higher per process.

https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94841 is a reply to message #94387] Sat, 04 February 2012 12:33 Go to previous messageGo to next message
Spacedust is currently offline Spacedust  Poland
Messages: 1233
Registered: October 2007
Location: Poland
Senior Master
I've made something better. Varnish before Lighttpd. It works perfectly Wink This will allow to switch from Lighttpd to Apache when Kloxo 6.1.11 will be released.
Re: Apache httpd config to compete with nginx and lighttpd [message #94943 is a reply to message #94841] Thu, 09 February 2012 10:24 Go to previous messageGo to next message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
I just revamped the code I am working on for this and missed a little mistake. Just wanted to warn anyone who was trying to test it. I think I will have a pretty good working driver ready sometime this weekend. I rewrote it in a way that should allow most of the existing apache driver code to still do it's tasks and work with my changes. I still plan to revamp the entire driver. I think that if I go over every single piece of it, I can better provide bug fixes in the future.

https://www.mercuryvps.com
HyperVM Xen VPS hosting
Re: Apache httpd config to compete with nginx and lighttpd [message #94974 is a reply to message #94943] Fri, 10 February 2012 20:41 Go to previous message
shazar is currently offline shazar  United States
Messages: 1856
Registered: May 2011
Grandmaster
LxCenter Core Team Member
LxCenter Representative
Ok see http://forum.lxcenter.org/index.php?t=msg&th=17844&g oto=94642&#msg_94642 for the instructions to test. No need to manually restart.

https://www.mercuryvps.com
HyperVM Xen VPS hosting
Previous Topic:Kloxo: Installing the Mono Framework
Next Topic:HOSTBILL AND KLOXO
Goto Forum:
  


Current Time: Wed Jun 19 23:46:10 EDT 2013

Total time taken to generate the page: 0.01400 seconds
.:: Contact :: Home :: Privacy ::.

Click here to lend your support to: LxCenter and make a donation at www.pledgie.com !

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software