Changes between Version 10 and Version 11 of soc/2007/cgi
- Timestamp:
- Jun 6, 2007, 1:16:47 AM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
soc/2007/cgi
v10 v11 19 19 { 20 20 cgi::request req; // set up the request 21 cgi::re sponse resp; // see Design Ideas for more about this21 cgi::reply rep; // see Design Ideas for more about this 22 22 23 re sp<< "Hello, " << req.param<cgi::GET>("user_name") << "!";24 re sp.send(req);23 rep<< "Hello, " << req.param<cgi::GET>("user_name") << "!"; 24 rep.send(req); 25 25 26 26 return 0; … … 32 32 int sub_main(cgi::request req) 33 33 { 34 cgi::re sponse resp; // see Design Notes for more about this34 cgi::reply rep; // see Design Notes for more about this 35 35 36 re sp<< "Hello, " << req.param<cgi::POST>("user_name") << "!";37 re sp.send(req);36 rep<< "Hello, " << req.param<cgi::POST>("user_name") << "!"; 37 rep.send(req); 38 38 39 39 return 0; … … 58 58 See [wiki:soc/2007/cgi/Concepts Concepts] for more. 59 59 60 '''Separation of ```cgi::request``` and ```cgi::re sponse```''':60 '''Separation of ```cgi::request``` and ```cgi::reply```''': 61 61 62 This separation is only a recent change. The main reasoning is that meta-data exists for both the request and the response. Using getters/setters is one idea, although in a large program, there could be a situation where you set a response header and then need to check it later. If everything was done with the ```request``` object then there'd be noway to achieve this.62 This separation is only a recent change. The main reasoning is that equivalent meta-data exists for both the request and the reply (ie. same identifier, different value). Using getters/setters is one idea, although in a large program, there could be a situation where you set a response header and then need to check it later. If everything was done with the ```request``` object then there'd be no clean way to achieve this. 63 63 64 64 Having two objects has other advantages: 65 65 * Code is clearer, without being too verbose 66 * Response caching is easier to implement; code can just cache a ```cgi::re sponse``` since it holds no data relevant to the specific request (note: response caching isn't really part of this project, although ```cgi::session``` will probably provide basic facilities)66 * Response caching is easier to implement; code can just cache a ```cgi::reply``` since it holds no data relevant to the specific request (note: response caching isn't really part of this project, although ```cgi::session``` will probably provide basic facilities) 67 67 68 68 '''Having the !CommonGatewayService control threading''' 69 69 70 * In order for the program initialisation time (ie. the time before the first request begins to be handled) to be kept to a minimum, pre-emptive multithreading is not an option. 71 * Users shouldn't have to implement complex event handling mechanisms in order to write a responsive, multiplexed application. 72 * Since CGI request handlers can take a long time to complete, having i/o and request handling done in the same threads can cause starvation of i/o. Giving a guarantee that handlers will only be called in threads calling ```basic_service<>::run()``` might cause this and other problems.[[BR]] 73 Options: 74 1. There should be threads calling ```basic_service<>::run()``` which handle input and output, and a separate set of threads which run the request handler provided by the user. 75 2. Only threads calling ```basic_service<>::run()``` should handle requests, but the service should be able to increase the number of threads calling run(). 76 3. If a user really wants all to be handled in the same threads, then passing a boost::thread_group to the service's constructor could provide a compromise: the user uses the thread_group to call ```basic_service<>::run()``` and the service uses it to dispatch request handlers. 77 * As a consequence of the above points, the number of running threads should be variable. Without this would lead to unresponsive programs if the user wasn't using a Proactive (ie. asynchronous) model or didn't have a good way of monitoring the service and adapting the number of threads. 78 * When threading support isn't available, a FastCGI application (for instance) should still 'just work', with request handlers running concurrently instead of in parallel. 79 80 '''Thread-pool vs. thread-per-request''' 81 82 ''Note: Since each connection can be multiplexing, it doesn't make sense to allow a thread-per-connection policy as this would make request response times inconsistent.'' 83 84 In general a thread pool will be more efficient than having a thread per request, especially if the reply is no more than a true/false statement (eg. in the Authorizer FastCGI role). A thread-per-request option should exist since thread local storage would be compromised using a thread pooling strategy, making an application less secure. 85 86 '''Single-threaded application''' 87 88 In the case of threading support not being available, all services should still work. Also, the style of the first example (above) should map to a FastCGI application by simply creating an ```fcgi_service``` first and then passing that to the ```cgi::request```'s constructor. 70 See [wiki:soc/2007/cgi/Dispatching Dispatching]. 89 71 90 72 == Main Classes ==