Forum OpenACS Development: ADP include multithreaded execution

I was wondering if there is a way to execute the rendering of includes in an adp file in a multithreaded way. What I mean is:

I have one ADP page. On this page there are 5 includes. I want AOLserver to compile the includes in parallel so the result is returned faster (if each include takes 500ms to render I want the job done in 700ms instead of 2500ms).

Any idea how to do this? Is this possible with AOLserver?

Collapse
Posted by Gustaf Neumann on
spawning threads for adp-includes is rather easy, the more complicated part is to collect the results of the threads in a asynchronous (non blocking) fashion and fill it in to the including template. I would do this with a collector thread via libthread with its event queues, where the connection thread spans a collector thread, which spans the worker threads (for the adp-includes) asynchonously. when all these worker threads are finished the collector returns the results to the waiting connection thread.

I am not sure, whether the 700ms are realistic, it might depend on the kind of machine you are using, .... but i would expect it to be faster than in sequential mode. are you thinking about the personal portal page of dotlrn or something else?

Collapse
Posted by Malte Sussdorff on
Hi Gustaf, thanks a lot for your answer but you totally lost me starting with the second sentence 😊. Do you mean I should go in the .tcl page and start individual threads to return the HTML code of each of the includes and then just insert this in the .adp page ?

All overview pages in contacts package and project-manager package are a collection of includes. As an example, the project-manager overview page has 10 includes from which to collect the data.

Collapse
Posted by Gustaf Neumann on
Malte,

if you start simply threads for snippets in a synchronous fashion (e.g. blocking until the result is computed) you gain nothing. One has to dispatch these asynchronously and collect the results, therefore the collector thread.

However, there is as well a much simpler approach to achieve similar results by using multiple connection threads to render a complex page. In general, this could be achieved with iframes, objects with html data, or ajax calls. just for fun, i implemented all three variants based on xowiki. I would think that the solution with background ajax calls is the most useful. It should be at least sufficient for you to get a better estimate whether you want to investigate further.

Update your xowiki from cvs and paste the following content into an xowiki page. You get roughly an output like the following
http://media.wu-wien.ac.at/download/xowiki-doc/view%20mySpace.png
where the portlets (adp includes) are rendered via separate connection threads. This requires some overhead over the sketched internal dispatch, but still, when computing the contents is slow, and you have plenty of processors, it might be better.

If you can split your complex page into multiple adp-includes, you can use these for testing in xowiki like in the page below...

>left-col<<
Gustaf Neumann This is the Personal Wiki-Page of Gustaf Neumann. This shows, how to place arbitrary text into a kind of Portal-Page developed as a wiki.

-gustaf neumann

{{adp portlet-ajax {title Groups portlet /dotlrn/dotlrn-main-portlet ID 1}}}
{{adp portlet-ajax {title MESSAGE KEY MISSING: 'forums-portlet.pretty_name' portlet forums-portlet ID 2}}}

><<

>right-col<<
{{adp portlet-ajax {title MESSAGE KEY MISSING: 'dotlrn-calendar.Day_Summary' portlet calendar-portlet ID 3}}}
><<
Collapse
Posted by Gustaf Neumann on
just to make it clear: in my previous posting the "MESSAGE KEY MISSING '...'" message were introduced by the forum, please replace it by sensible titles if you want to try this example with cut&paste.
Collapse
Posted by Dave Bauer on
It would be alot easier and straightforward, and I suspect, maintainable, if you just made the queries faster :)
Collapse
Posted by Malte Sussdorff on
Well, query execution time is not the issue here. I might have stressed the truth a bit with the 500ms, e.g. the projects page loads in 1.5seconds with the slowest query taking around 100ms. But as we are executing 130db queries on that page with 8 includes, I thought that having them rendered in parallel will make better use of the parallel execution capabilities of postgresql. At the moment we have 30 DB connections to the database and on average we use around 5 of these. So parallelization will make better use of the resources available, as we do not have many users in the system, but a ton of data.
Collapse
Posted by Malte Sussdorff on
Oh, and out of the 130 queries only 10 are slower than 10ms.
Collapse
Posted by Andrew Piskorski on
Malte, why would you want to do that? Why is generating your ADP page taking 2.5 seconds in the first place, where is the time being taken up? Can the serial code be sped up? Are these includes cached after first use or does producing them take the full 2.5 s every time?

And just how many CPUs does your server have? If you are on a typical 2 cpu server, I would think that using both cpus to concurrently render a single ADP page would be a fairly bad idea even if you could make it work.