in reply to Multithreaded (or similar) access to a complex data structure
Up front. I've done very little CGI/webserver stuff at all.
That said, I think that you are breaking the cardinal rule of presentation layer work, by mixing your presentation layer code and your 'application logic' code together in your CGI code.
(IMO) your application should be split into two distinct parts:
This is a process that talks to your DB (and any other places it gets information) to build and maintain your datastructure.
And periodically -- once a minute or once every 10 seconds or whatever frequency makes sense -- uses the information it holds to write a formatted web page to the web servers filesystem.
This is a standard CGI or mod_perl script that when it receives a connection, just reads the latest formatted page from the file system and sends it to the browser.
By disconnecting the production of the page from the connections to the webserver, you ensure that no matter how thick and fast the connections arrive you can deal with them in a timely manner whilst imposing minimal load on your critical, public-facing front end, because they are in effect just responding with a static page. The latest updated version that is available. It also ensure that you don't hammer your DB requesting the same information over and over for every page request that arrives.
Indeed, you could do away with the cgi completely and serve the webpage directly from the file-system though I don't know how the webserver would handle it if the file was in the process of being written when a request came in?
And by disconnecting the production of the page from inbound requests, it allows you to choose the frequency with which you update that page. Whether that be on the basis of every few seconds, or when a significant event occurs or whatever makes sense to your application. And you only need to maintain one copy of your complex data structure in memory.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multithreaded (or similar) access to a complex data structure
by FloydATC (Deacon) on Nov 07, 2011 at 06:00 UTC | |
by BrowserUk (Patriarch) on Nov 07, 2011 at 11:56 UTC | |
by FloydATC (Deacon) on Nov 08, 2011 at 07:54 UTC | |
by BrowserUk (Patriarch) on Nov 08, 2011 at 14:46 UTC |