منتدى استراحات زايد

منتدى استراحات زايد (http://vb.ma7room.com/index.php)
-   منتدى أخبار المواقع والمنتديات العربية والأجنبية (http://vb.ma7room.com/forumdisplay.php?f=183)
-   -   Quick Fix for Slow Websites (http://vb.ma7room.com/showthread.php?t=257150)

محروم.كوم 10-28-2009 03:10 AM

Quick Fix for Slow Websites
 
Edit: Don't go around changing Apache settings on production servers if you don't know what you're doing. I hope this info helps someone* but I'm not responsible if the info below causes your server to violently explode.

We recently had an issue where our more heavily-loaded servers would get sluggish at certain peak times of the day* or when getting hammered by various spiders. I made a simple change in our Apache configuration that made a world of difference. In the #phpwebsite channel* a user was complaining of poor performance on a server with 185 branches on it* and this configuration change provided "a noticeable difference right away".

So I figured I'd share it here. :D If you're running phpWebSite on an Apache server (using the default MPM* prefork.c) and you're having performance issues* try this! It's quick and easy and may solve your problem.

Look for a section in your Apache configuration that looks like this:

Code:

StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000

This is the default for Fedora and RHEL* yours may be different on other distros. This section of your configuration is actually very important. Apache's stability and speed is reliant on having multiple server processes running at any given time. One server process can only handle one client request at a time* so it's important to have enough running to service your users* but not so many that you're out of system resources. So basically* you read this section like so:

Start with 8 servers running.
Never have less than 5 servers idling (running but not serving requests).
Never have more than 20 servers idling
Never spawn more than 256 servers
Never allow more than 256 client connections at a time
After a server process has handled up to 4*000 client requests* kill it off and spawn a new one

All of these settings are immensely important (particularly if you're on a resource-starved setup)* but MaxRequestsPerChild is very interesting. You don't want to set this too low* because it takes a lot of CPU time as well as memory to get a process started. It's kind of like starting a car - you don't want to do it every time you stop and go* because that's bad for your engine and your gas mileage.

On the other hand* a server process can build up a lot of gunk over time. PHP has some memory leaks* and Apache probably does too. The process is also maintaining a database connection pool. There's a lot of other things going on. Killing the server process and starting a new one clears up all of these potential messes and starts from a clean slate.

So I set this setting to around 50. I've found that this is high enough (for our traffic levels) that it's not constantly stopping and starting* but low enough that processes do get killed off every now and then. If you're on a higher-traffic or simpler site* you may want to set it higher. If you're on a lower-traffic or more complex site* you may want to set it lower.

tl;dr: in httpd.conf or apache.conf* set MaxRequestsPerChild to around 50 for the prefork.c MPM.


الساعة الآن 03:53 AM

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2 TranZ By Almuhajir


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227