comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Structure of the multitasking server
Date: Mon, 22 Sep 2008 10:12:44 +0200
Date: 2008-09-22T10:12:44+02:00	[thread overview]
Message-ID: <1ey0wvc4tun7g$.15u4xyef05055$.dlg@40tude.net> (raw)
In-Reply-To: c544022f-9732-4090-8ee3-a2fccecb9cf3@i76g2000hsf.googlegroups.com

On Sun, 21 Sep 2008 14:27:13 -0700 (PDT), Maciej Sobczak wrote:

> On 21 Wrz, 21:24, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>> On Sun, 21 Sep 2008 10:30:37 -0700 (PDT), Maciej Sobczak wrote:
> 
>>> No problem with that. With separate protected object (instead of
>>> rendezvous) it is enough to do this:
>>
>> Of course there is a problem because conditional and timed entry calls may
>> not contain a "terminate" alternative.
> 
> They don't have to. Again:
> 
>       entry Get_Job (J : out Job_Type; Finished : out Boolean);

Which is a bad pattern because it propagates task termination requests to
an entry point of some object (or another task) which usually have little
or nothing to do with the task termination issue.

I don't like an extra output parameter, it is error-prone. Therefore I used
a special value of Job_Type. There also exists a third variant with an
exception propagation. (Note that an exception from an rendezvous
propagates on both sides)

This all is a matter of taste, because the (poor) pattern is same: the
knowledge about caller's termination is moved to the callee.

>> you have server, workers, channels and management stuff.
> 
> Because it *is* there anyway.
> Trying to hide it? What about the following: in my version the main
> task (the one that invents jobs) can give the job to the worker task
> when it is still working on the previous one, so that the main task
> need not be blocked and can go on inventing more jobs.

This is a very different task. You didn't say that you wanted to queue
jobs. Anyway there is little sense to queue jobs to busy workers. A better
design would be:

   Server --> Scheduler <-- Worker

The jobs are queued to the scheduler. Workers ask it for jobs to do.
Scheduler could be a protected object or a task. Depending on the nature of
the jobs source, Server and Scheduler can be merged (see below).

> This is not so easy in your version with rendezvous, where the main
> task has to always *wait* until some of the worker will be willing to
> pick up the new job (that's the whole point of rendezvous).

You *have* to wait, or else you must drop jobs.

Queueing jobs postpones the problem but that by no means solves it. If
workers are incapable to process the jobs, the server must wait for them.
The only reason why job queueing might become necessary is a need to make
the server asynchronously working. (Remember our recent discussion?
Buffering = wasting resources, unless decouples.)

Anyway it is no problem in my design. Use selective accept (RM 9.7.1):

   select
      when not Empty (Queue)  => accept Get (Work : out Job) do
         ... -- A worker is here to get a job from the FIFO
      end Get;
   or when not Full (Queue) => accept Put (Work : out Job) do
         ... -- A new job is to queue into the FIFO
      end Put;
   or when Full (Queue) => delay Time_Out;
      ... -- Go to hell with your jobs!
   end select;

> Obviously,
> there are fewer opportunities for concurrency in your version.
> What would you have to do to have this increased concurrency in your
> version? Would you still claim it to be simpler?

Certainly yes. If I wished to collect jobs at the server I would just add a
FIFO of jobs there, like above.

>> The second problem which adds complexity is server to worker 1-n
>> communication. Should be n-1 worker to server, simpler (classic
>> client-server) and more efficient too.
> 
> I'd prefer producer + queue + N consumers. Still a protected object in
> the middle.

What you describe is my design (the queue is held by the producer).Your
design was:

   producer + N queues of size 1 + N consumers

It is not a problem to me to split the producer into server and scheduler.
I object mainly to moving *parts* of the scheduler (as protected objects)
into the consumers. It makes no sense.

>>> There is no need to introduce any special type of job ("poison pill").
>>
>> Job carries the parameters of a worker. You used it too, under the name
>> Job_Type.
> 
> But in my case the Job_Type need not contain the special "poison"
> value.

See above. You can use either of three variants with my design. This is an
independent issue.

> Let's say that the Job_Type is a matrix that has to be
> reversed. There is no place for the "poison" value in the matrix
> itself, so the Job_Type would need to be extended (a record with
> additional flag, perhaps?) to cover it, but then the pollution of the
> type would be very explicit.

If it were large objects, I would not use copying anyway. So it would
become a referential object moving around. These would have enough place
for "poison". Further, don't forget that Ada has variant records.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-09-22  8:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-19 12:21 Structure of the multitasking server Maciej Sobczak
2008-09-19 13:34 ` Jean-Pierre Rosen
2008-09-19 17:02   ` Dmitry A. Kazakov
2008-09-21 17:30     ` Maciej Sobczak
2008-09-21 19:24       ` Dmitry A. Kazakov
2008-09-21 21:27         ` Maciej Sobczak
2008-09-22  8:12           ` Dmitry A. Kazakov [this message]
2008-09-22 12:47             ` Maciej Sobczak
2008-09-22 14:11               ` Dmitry A. Kazakov
2008-09-23  8:07                 ` Maciej Sobczak
2008-09-23  9:37                   ` Dmitry A. Kazakov
2008-09-23 10:47                   ` Jean-Pierre Rosen
2008-09-21 17:23   ` Maciej Sobczak
2008-09-22  8:23     ` Jean-Pierre Rosen
2015-03-12 16:07   ` gautier_niouzes
2015-03-12 21:38     ` Jacob Sparre Andersen
2015-03-12 22:39       ` gautier_niouzes
2015-03-13  8:15         ` Dmitry A. Kazakov
2015-03-13 20:16           ` gautier_niouzes
2015-03-13 20:47             ` Dmitry A. Kazakov
2015-03-15  7:43               ` gautier_niouzes
2015-03-15  8:35                 ` Simon Wright
2015-03-15  8:52                 ` J-P. Rosen
2015-03-15  9:21                   ` Jacob Sparre Andersen
2015-03-15 16:04                     ` Brad Moore
2015-03-13 23:04             ` Randy Brukardt
2015-03-14  8:22               ` Simon Wright
2008-09-19 23:01 ` anon
2008-09-21 17:37   ` Maciej Sobczak
2008-09-22  2:32     ` anon
2008-09-22 13:05       ` Maciej Sobczak
2008-09-23  9:25         ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox