The question of 'which server model should I use' is a very complicated one, and I doubt you will find a consistent answer from different people for 'which way is best?'
For the most basic overview:
- One process per connection: Medium capacity. Simple to implement and maintain. On UNIX platforms, data can be shared between clients in a restricted manner using shared memory segments. Another alternative would be a database backend. Active connection limit restricted by maximum number of process that can be executed on system at one time. If one process dies due to an implementation error, other process remains active and unaffected.
- One thread per connection: Medium->Large capacity. Data is easily shared between clients. Active connection limited restricted by maximum number of threads that can be executed on system at one time. If Perl ITHREADS are used, special consideration should be taken to understand the cost of creating a thread (Perl data structure copying, etc.). Cost can be minimized by utilizing a thread pool, instead of creating a new thread for each connection.
- One process, switched connections:Medium->Large capacity if implemented correctly. Correct implementation is difficult as each connection must be managed by a state machine-like device, event handlers need to be broken into small pieces, and some events need to be prioritized. Data is easily shared between clients. Implementation errors have the greatest chance of affecting all active connections when compared to any of the other models.
- Multiple processes, connection loop:This is the model used by the Apache web server. The principle is that multiple processes actually wait on accept(), and the first one to succeed, gets the connection, and handles the connection completed. An outer processes ensures that sufficient processes are waiting on the listening socket. This model is very resistant to most implementation errors, and is very efficient. Where other models require multiple system calls to handle a connection (accept()/fork(), accept()/pthread_create(), select()/accept()), this model requires only one system call: accept(). Client data must be accessed as per the 'One process per connection' model.
In terms of portability, all models should function to different degrees. My personal attachment is the 'One process, switched connections' model, however, due to its complexity, I would not recommend it to those personally unfamiliar with the issues involved. If you have not ever used non-blocking I/O, I recommend that the 'One process, switched connections' model not be considered.
This description is far from complete, but it should provide you with rough expectations. Notice that I did not label any of these solutions 'Large capacity'. Any implementation that truly needs 'Large capacity' should not be written in Perl. By 'Large capacity', I mean 10000+ connections per minute sustained.
WIN32 NOTE: Take into account that fork() is implemented using Perl ITHREADS under WIN32. Therefore, although all multiple process models should function under WIN32, it is probably better to consider implementing the solutions using Perl threads to avoid the 'emulation' layer.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.