Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

[Info] Apache Optimisation

Image hosting site apache

6:29 pm on Aug 4, 2012 (gmt 0)


I have a site of a free images hosting hosted in a VPS:

CPU: 4 Core AuthenticAMD, QEMU Virtual CPU version 1.0.50
cpu MHz : 2199.998
cache size : 512 KB

With my site i use Cloudflare, a free CDN service that cache me all the images.

My site is growing very fast and now every day i counsume 4 TB of bandwitdh with 18.000.000 hits. (With cloudflare i consume low Gb of BW because it caches all)

Now i overloaded their server, so they disabled my account, that's normal. I have like 1 week and after they will block my account.

So now i must handle 18.000.000 request with apache.

Is that possible? I tried to disable Cloudflare, and my site goes offline cause of lot of request.

I think that it's not a problem of VPS, my CPU load max is 20% and i have always 20% of RAM free (this when i disable cloudflare).

Apache crash with this message "server reached MaxClients setting, consider raising the MaxClients setting". Only if i reactive Cloudflare, the site goes up.

These are my config about Maxclients:

<IfModule prefork.c>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 150
MaxClients 150
MaxRequestsPerChild 150

I used netstat too see the connection when the site goes offline, at 1700 connection. (it overcome the 2200 but with site offline, or with trasfer very slow, like half site loaded after 5 minutes)

I used apache server-status, here the statistic. This log is when cloudflare is active, if i deactive it in little seconds there are hundres (maybe thousand) apache connection.


This log is when i disable cloudflare (i printed this log after 1 second after i disabled cloudflare, because after 5 seconds site goes offline)


Hope you will propouse some solution,
Thank you

[edited by: incrediBILL at 3:38 am (utc) on Aug 5, 2012]
[edit reason] removed URLS, see TOS & Charter - paste all relevant data in post [/edit]

10:21 pm on Aug 4, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

You could ditch Apache and use nginx or lighttpd to serve your images and other static content, but isn't bandwidth your main issue? What provider will give you 120TB of bandwidth a month with a VPS package like the one you've got now? You'll probably be spending thousands of dollars a month.

I hope you weren't expecting to be able to use CloudFlare for free with that kind of traffic... but you could (perhaps should) ask them what they can do for you when you become a paying customer. However, I don't think their site acceleration service is meant to be used in this way.
10:51 pm on Aug 4, 2012 (gmt 0)

Hello robzilla, thank you for the answer. I had a friend with the same "problem" with Cloudflare so i knew that the account would be disabled on short time.

About VPS i'm not spending a lot of $ because the site is hosted in a network that is our affiliation (i Use three different VPS for site/mysql/mail/blog). The problem is not the bandwidth but only the possibility to handle the request with Apache.

It's not possible use lighttpd or nginx cause of our script.

9:25 am on Aug 5, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

You're saying 120,000 GB/month is not a problem? Do you have an unmetered 100Mbps connection?

If you can't ditch Apache entirely (I'm assuming because of rewrite rules, though these can be adapted), you can add nginx as a reverse proxy in front of Apache to handle all static resource requests. I don't think your current setup will be able to handle an average of 200 requests/sec with those specs, no matter how you configure Apache. Obviously, if you want to squeeze as much out of this server as you can, you will need to increase MaxClients and ServerLimit to the point where your server can just handle it without crashing -- if right now you only have 20% RAM free, however, you won't be able to serve many more clients without upgrading.
10:06 am on Aug 5, 2012 (gmt 0)

Thank you, yes i'm starting to do nginx as a proxy. I will tell you the result.
1:36 pm on Aug 5, 2012 (gmt 0)

I'm running now the site with ngnix and seems to be better, i mean that there isn't crash. But always very very slow site. How i disable Cloudflare after 1 minute the site start to become very slow like 1 minute to load the page.

There is the possibility to block the bandwitdh (load) for an images that for example overcome 200 request in a minute?

Because some images are posted on popular site like Facebook, and i want that only first 200 users can see the image, the others must wait some times to see it.

This i think can save some bandwitdh and server load.

Thank you for help.
5:10 pm on Aug 5, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

How did you configure nginx? Did you set up at least four worker_processes? Did you turn off keepalive? Are you setting caching headers aggressively?

What do your CPU and memory stats look like when the site is slow like that?

I'm not aware of a possibility to limit the number of times a resource is accessed. I'm sure it's possible somehow, but probably not your best option.
5:18 pm on Aug 5, 2012 (gmt 0)

I incresed the worker_connections to 50.000, i turned of keepalive, enable cache mod and gzip.

What is wowrker_process?

I configured also these three mods that can help me to manage bandwitdh.

Limit band for country
5:50 pm on Aug 5, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Just make sure you set those properly, if you use them.

The number of worker_processes is set in nginx.conf and defines the number of slave processes that will be handling requests. A decent rule of thumb is that you should have at least one per processor core. Note that the number of worker processes is multiplied by the number of allowed worker connections; with 4 cores, you would theoretically max out at 200.000 connections, but you'll probably run out of memory sooner, or run into other server limits.

Featured Threads

Hot Threads This Week

Hot Threads This Month