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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>15. Deploying your website for production</title>
<META NAME="description" CONTENT="15. Deploying your website for production">
<META NAME="keywords" CONTENT="tut">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="tut.css" type='text/css'>
<link rel="first" href="tut.html">
<link rel="contents" href="contents.html" title="Contents">
<LINK REL="next" HREF="node18.html">
<LINK REL="previous" HREF="node16.html">
<LINK REL="up" HREF="tut.html">
<LINK REL="next" HREF="node18.html">
<meta name='aesop' content='information'>
</head>
<body>
<DIV CLASS="navigation">
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node16.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="tut.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node18.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Tutorial</td>
<td><A HREF="node2.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node16.html">14. Special variables and</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="tut.html">CherryPy Tutorial</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node18.html">16. And now what</A>
<br><hr>
</DIV>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="node17.html#SECTION0017100000000000000000">15.1 Choosing you deployment configuration</a>
<UL>
<LI><A href="node17.html#SECTION0017110000000000000000">15.1.1 Should I use the CherryPy HTTP server directly or behind another webserver like Apache ?</a>
<UL>
<LI><A href="node17.html#SECTION0017111000000000000000">15.1.1.1 Use it directly</a>
<LI><A href="node17.html#SECTION0017112000000000000000">15.1.1.2 Use it behind Apache</a>
</ul>
<LI><A href="node17.html#SECTION0017120000000000000000">15.1.2 Options for deploying CherryPy directly</a>
<UL>
<LI><A href="node17.html#SECTION0017121000000000000000">15.1.2.1 Single thread/process</a>
<LI><A href="node17.html#SECTION0017122000000000000000">15.1.2.2 Forking server</a>
<LI><A href="node17.html#SECTION0017123000000000000000">15.1.2.3 Threading server</a>
<LI><A href="node17.html#SECTION0017124000000000000000">15.1.2.4 Process pool</a>
<LI><A href="node17.html#SECTION0017125000000000000000">15.1.2.5 Thread pool</a>
<LI><A href="node17.html#SECTION0017126000000000000000">15.1.2.6 Other alternatives</a>
</ul>
<LI><A href="node17.html#SECTION0017130000000000000000">15.1.3 Options for deploying CherryPy behind another webserver</a>
</ul>
<LI><A href="node17.html#SECTION0017200000000000000000">15.2 Configuration file options</a>
</ul>
<!--End of Table of Child-Links-->
<HR>
<H1><A NAME="SECTION0017000000000000000000">
15. Deploying your website for production</A>
</H1>
<P>
So there you are, with a nice big website you've spent weeks working on. And it's finally ready for the world to use it !
<P>
But you still have to decide how you will <b>deploy</b> it, which means: how will you set it up on the production
machine(s).
<P>
<H1><A NAME="SECTION0017100000000000000000">
15.1 Choosing you deployment configuration</A>
</H1>
<P>
When you are developing your website, you're usually the only one (maybe with a few other developers) accessing the website,
so it doesn't need to be fast and robust. But on the production website, many people (if you're lucky) will access your
website. This means that you have to choose the proper CherryPy configuration in order to provide a fast/reliable service to
your users.
<P>
Criteria to help you choose your configuration include:
<UL>
<LI><b>What does you hosting provider let you do ?</b> If you're on a shared machine, you might not be able to do what you want.
For instance, you may only be able to use CGI, and your hosting provider may only provide virtual hosting, behind Apache.
</LI>
<LI><b>How much traffic do you plan to get ?</b> Do you plan to have only a few hundreds users per day or several tens of thousands ?
</LI>
<LI><b>How many machines/processors do you have ? (ie: how much money do you have)</b> If you plan to have a lot of traffic,
then you might have to use several machines/processors (which means higher cost).
</LI>
<LI><b>Will there be a webmaster looking after the website ?</b> If you don't have anyone looking after the website at all
time, you might want the website to restart automatically in case of a crash.
</LI>
</UL>
<P>
<b>Note that there is a HowTo called "Sample deployment configuration for a
real-world website" that shows a full sample configuration that is
recommended for most websites.</b>
<P>
<H2><A NAME="SECTION0017110000000000000000">
15.1.1 Should I use the CherryPy HTTP server directly or behind another webserver like Apache ?</A>
</H2>
The first decision to make is whether to use the CherryPy HTTP server directly or behind another webserver like Apache.
Here is a list of advantages for each method:
<H3><A NAME="SECTION0017111000000000000000">
15.1.1.1 Use it directly</A>
</H3>
<UL>
<LI>Is faster and uses less ressources (no Apache processes and no need to talk between Apache and CherryPy)
</LI>
<LI>Is easier to set up
</LI>
</UL>
<H3><A NAME="SECTION0017112000000000000000">
15.1.1.2 Use it behind Apache</A>
</H3>
<UL>
<LI>Might be faster for serving static content (like images)
</LI>
<LI>Hosting provider might force you to use Apache
</LI>
</UL>
<P>
Once you've decided if you wanted to use CherryPy directly or behind another webserver, you still have to decide among
several configurations...
<P>
<H2><A NAME="SECTION0017120000000000000000">
15.1.2 Options for deploying CherryPy directly</A>
</H2>
The following subsections show you what the different options are and what the advantages/drawbacks are:
<H3><A NAME="SECTION0017121000000000000000">
15.1.2.1 Single thread/process</A>
</H3>
<b>Explaination</b>: This means that the CherryPy HTTP server will run in one single thread/process. While
it is handling a request, no other request can connect to it during that time.
<P>
Advantages:
<UL>
<LI>Fast for each request (no need to create a thread/process for each request)
</LI>
</UL>
Drawbacks:
<UL>
<LI>Cannot handle concurrent requests
</LI>
</UL>
<b>Conclusion</b>: This method is the default configuration and it works fine for development, but it should be banned
for production if you might have several users accessing your website at the same time.
<P>
<H3><A NAME="SECTION0017122000000000000000">
15.1.2.2 Forking server</A>
</H3>
<b>Explaination</b>: This means that the CherryPy HTTP server will create a new process to handle each request.
After the response is sent back, the process is destroyed.
<P>
Advantages:
<UL>
<LI>Can handle multiple requests at a time
</LI>
<LI>On a multiprocessor machine, a forking server will take advantage of the several processors
</LI>
</UL>
Drawbacks:
<UL>
<LI>Might be expansive to create a new process for each request (especially if requests come in very fast)
</LI>
<LI>Forking doesn't work on Windows
</LI>
<LI>Cannot easily use sessions as session data cannot be easily shared among processes
</LI>
</UL>
<b>Conclusion</b>: This method can be used on non-Windows machines if the website's traffic isn't too high.
<P>
<H3><A NAME="SECTION0017123000000000000000">
15.1.2.3 Threading server</A>
</H3>
<b>Explaination</b>: This means that the CherryPy HTTP server will create a new thread to handle each request.
After the response is sent back, the thread is destroyed.
<P>
Advantages:
<UL>
<LI>Can handle multiple requests at a time
</LI>
<LI>Works on all platforms (including Windows)
</LI>
</UL>
Drawbacks:
<UL>
<LI>Might be expansive to create a new thread for each request (although less expensive than processes),
especially if requests come in very fast
</LI>
<LI>On a multiprocessor machine, a threading server will <b>not</b> take advantage of the several processors (due to the Python
global interpreter lock)
</LI>
</UL>
<b>Conclusion</b>: This method can be used if the website's traffic isn't too high.
<P>
<H3><A NAME="SECTION0017124000000000000000">
15.1.2.4 Process pool</A>
</H3>
<b>Explaination</b>: This means that the CherryPy HTTP server will create a fixed number of processes at startup, and
these processes will remain all the time. If one process if busy handling a request and another request comes in, then the
next process will step up and handle it.
<P>
Advantages:
<UL>
<LI>Can handle multiple requests at a time
</LI>
<LI>Fast because we don't need to create a thread or process for each request
</LI>
<LI>Takes advantage of multi-processor machines
</LI>
</UL>
Drawbacks:
<UL>
<LI>Doesn't work on Windows
</LI>
<LI>Cannot easily use sessions as session data cannot be easily shared among processes
</LI>
</UL>
<b>Conclusion</b>: This method works well on non-Windows machines, as long as you don't have hundreds of concurrent users.
<P>
<H3><A NAME="SECTION0017125000000000000000">
15.1.2.5 Thread pool</A>
</H3>
<b>Explaination</b>: This means that the CherryPy HTTP server will create a fixed number of threads at startup, and
these threads will remain all the time. If one thread if busy handling a request and another request comes in, then the
next thread will step up and handle it.
<P>
Advantages:
<UL>
<LI>Can handle multiple requests at a time
</LI>
<LI>Fast because we don't need to create a thread or process for each request
</LI>
</UL>
Drawbacks:
<UL>
<LI>Doesn't take advantage of multi-processor machines.
</LI>
<LI>Number of threads doesn't increase if we have more concurrent users.
</LI>
</UL>
<b>Conclusion</b>: This method works very well and it is the recommended set-up in many cases (as long as you don't have hundreds of concurrent users).
<P>
<H3><A NAME="SECTION0017126000000000000000">
15.1.2.6 Other alternatives</A>
</H3>
If you <b>really</b> have a lot of traffic and the previous methods are not enough or you can not use them (if you're on
Windows for instance), then you can use generic load-balancing. There is a HowTo in the documentation about it.
<P>
<H2><A NAME="SECTION0017130000000000000000">
15.1.3 Options for deploying CherryPy behind another webserver</A>
</H2>
All the configurations described in the previous section are also available when deploying CherryPy behind another webserver.
The third-party webserver will generally be multi-threaded or multi-processes. There is a HowTo in the
documentation that explains how to set this up.
<P>
<H1><A NAME="SECTION0017200000000000000000">
15.2 Configuration file options</A>
</H1>
Here is the list of the configuration file options that are used to specify how the CherryPy server will be deployed. All
these options are used within the <var>[server]</var> section of the configuration file (cf Chapter "Configuring CherryPy").
<UL>
<LI><b>socketPort</b>: This indicates which port the server should listen to. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
</pre></div>
</LI>
<LI><b>socketHost</b>: This indicates which address the server should bind to (the default is localhost). Example:
<div class="verbatim"><pre>
[server]
socketHost=192.168.0.23
</pre></div>
</LI>
<LI><b>socketFile</b>: This is only used on Unix, if you want to use an AF_UNIX socket instead of a regular AF_INET socket. Example:
<div class="verbatim"><pre>
[server]
socketFile=/tmp/mySocket.soc
</pre></div>
</LI>
<LI><b>forking</b>: Set this to 1 if you want a forking server. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
forking=1
</pre></div>
</LI>
<LI><b>threading</b>: Set this to 1 if you want a threading server. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
threading=1
</pre></div>
</LI>
<LI><b>processPool</b>: Set this to n (n>1) if you want to have n processes created at startup. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
processPool=10
</pre></div>
</LI>
<LI><b>threadPool</b>: Set this to n (n>1) if you want to have n threads created at startup. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
threadPool=10
</pre></div>
</LI>
<LI><b>reverseDNS</b>: Set this to 1 if you want to enable reverse DNS (this way the full name of the domain name for the clients will be written to the logs). The default is 0. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
reverseDNS=1
</pre></div>
</LI>
<LI><b>socketQueueSize</b>: Size of the socket queue (this value will be passed to the listen() function). The default is 5. Example:
<div class="verbatim"><pre>
[server]
socketPort=80
socketQueueSize=5
</pre></div>
</LI>
<LI><b>sslKeyFile and sslCertificateFile</b>: This is used to have an SSL server. There is a HowTo in the documentation about it.
</LI>
<LI><b>xmlRpc</b>: This is used to have an XML-RPC server. There is a HowTo in the documentation about it.
</LI>
</UL>
<P>
Some of these options obviously cannot be used together because they conflict:
<UL>
<LI><b>socketFile</b> and <b>socketPort</b> obviously conflict with each other
</LI>
<LI><b>threading</b>, <b>forking</b>, <b>processPool</b> and <b>threadPool</b> obviously conflict with each other
</LI>
</UL>
<P>
<DIV CLASS="navigation">
<p><hr>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A HREF="node16.html"><img src="../icons/previous.gif"
border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="tut.html"><img src="../icons/up.gif"
border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A HREF="node18.html"><img src="../icons/next.gif"
border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">CherryPy Tutorial</td>
<td><A HREF="node2.html"><img src="../icons/contents.gif"
border="0" height="32"
alt="Contents" width="32"></A></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
<td><img src="../icons/blank.gif"
border="0" height="32"
alt="" width="32"></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" HREF="node16.html">14. Special variables and</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="tut.html">CherryPy Tutorial</A>
<b class="navlabel">Next:</b> <a class="sectref" HREF="node18.html">16. And now what</A>
<hr>
<span class="release-info">Release 0.10, documentation updated on 19 March 2004.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
|