Balanced process processing 
Author Message
 Balanced process processing

I'm maintaining test code that attempts to send messages from multiple
processes to the same object to ensure concurrency issues are handled
properly by semaphores. In doing so, I've observed some differences between
how VisualAge and VisualWorks balance the processing load between multiple
processes of the same priority. VW processing is easily balanced while VA
doesn't provide any way to balance processing. Here is the test code I used
for both VW and VA:

| answers loop processes |
loop := true.
processes := 10.
answers := Array new: processes .
[
 1 to: processes do: [:i |
  answers at: i put: 0.
  [  [loop] whileTrue:

   answers at: i put: (answers at: i) + 1.
   Processor yield.
  ]] fork.
 ].
 (Delay forSeconds: 5) wait.
] valueNowOrOnUnwindDo: [ loop := false ].
self gbsMessager
 comment: '%1 processes yielding\ results: %2\ total: %3.'
 with: processes
 with: answers
 with: (answers inject: 0 into: [:ea :sum | sum + ea ]).

Results for VisualWorks 3.0:

10 processes yielding
 results: #(38453 38453 38453 38453 38453 38453 38452 38452 38452 38452)
 total: 384526.
100 processes yielding
 results: #(3150 3150 3150 3150 3150 3150 3150 3150 3150 3150 3150 3150 3150
3150 3150 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149
3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149
3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149
3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149
3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149
3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149 3149)
 total: 314915.

Results for VisualAge 4.5:

10 processes yielding
 results: (1 2 3 4 5 6 7 8 9 1053354)
 total: 1053399.
100 processes yielding
 results: (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
943939)
 total: 948889.

On a related topic, I was surprised to find that the
ProcessorScheduler>>yield method in VA is marked private. IBM doesn't seem
to provide a public way to say that the active process may yield processing
time to other processes. Isn't this a mistake?

You can get the code to work without using "Processor yield" but only if you
run the looping threads at a lower priority than the terminating (main)
thread. The result is unbalanced processing for both VA and VW--it doesn't
meet the requirements. Here are example code and results:

| answers loop processes |
loop := true.
processes := 10.
answers := Array new: processes .
[
 1 to: processes do: [:i |
  answers at: i put: 0.
  [  [loop] whileTrue:

   answers at: i put: (answers at: i) + 1.
  ]] forkAt: Processor activePriority - 1.
 ].
 (Delay forSeconds: 5) wait.
] valueNowOrOnUnwindDo: [ loop := false ].

self gbsMessager
 comment: '%1 processes\ results: %2\ total: %3.'
 with: processes
 with: answers
 with: (answers inject: 0 into: [:ea :sum | sum + ea ]).

Results for VisualWorks 3.0:

10 processes
 results: #(7756887 0 0 0 0 0 0 0 0 0)
 total: 7756887.

Results for VisualAge 4.5:

10 processes
 results: (0 0 0 0 0 0 0 0 0 11029021)
 total: 11029021.

Since natural processing (without #yield) seems to give such unbalanced
attention to other processes for both VA and VW, I wonder how much real
multi-threading there really is going on. Or more precisely, what conditions
in both VA and VW cause other processes of the same priority to get
attention? It seems it should be yields, delays, process control objects
(such as Semaphores), and perhaps some other activities or events.

A second observation is that Delay in VA doesn't give processing to other
processes (like VW does). Here are the code and results:

| answers delay loop processes |
loop := true.
delay := 10.
processes := 10.
answers := Array new: processes .
[
 1 to: processes do: [:i |
  answers at: i put: 0.
  [  [loop] whileTrue:

   answers at: i put: (answers at: i) + 1.
   (Delay forMilliseconds: delay) wait.
  ]] fork.
 ].
 (Delay forSeconds: 5) wait.
] valueNowOrOnUnwindDo: [ loop := false ].
self gbsMessager
 comment: '%1 processes delaying for %2ms\ results: %3\ total: %4.'
 with: processes
 with: delay
 with: answers
 with: (answers inject: 0 into: [:ea :sum | sum + ea ]).

Results for VisualWorks 3.0:

10 processes delaying for 0ms
 results: #(3088 3088 3090 3090 3090 3090 3088 3089 3090 3089)
 total: 30892.
10 processes delaying for 1ms
 results: #(2508 2508 2508 2508 2508 2508 2508 2508 2507 2507)
 total: 25078.
10 processes delaying for 10ms
 results: #(466 466 466 466 465 465 465 465 465 465)
 total: 4654.

Results for VisualAge 4.5:

10 processes delaying for 0ms
 results: (1 1 1 1 1 1 1 1 1 511)
 total: 520.
10 processes delaying for 1ms
 results: (1 1 1 1 1 1 1 1 1 511)
 total: 520.
10 processes delaying for 10ms
 results: (1 1 1 1 1 1 1 1 1 511)
 total: 520.

VisualAge uses "Processor enableAsyncMessages: false" in Delay>>wait to
prevent other processes from getting any processing time while there is a
delay (why?). A delay in VA seems to be for all processes of the same
priority while a delay in VW is for the active process. I would expect Delay
to behave as it does in VW.

VA doesn't seem to give time to processes of equal priority by using neither
delays nor yields. My thoughts are that VW is better for multi-threaded
applications than VA. I would expect VA to hide problems in poorly written
multi-threaded applications because there would likely be fewer
opportunities for concurrency collisions. VA seems to achieve better
performance but neglects other processes of the same priority. Any comments
or preferences?

Paul Baumann



Wed, 18 Jun 1902 08:00:00 GMT  
 Balanced process processing

Quote:

>I'm maintaining test code that attempts to send messages from multiple
>processes to the same object to ensure concurrency issues are handled
>properly by semaphores. In doing so, I've observed some differences between
>how VisualAge and VisualWorks balance the processing load between multiple
>processes of the same priority. VW processing is easily balanced while VA
>doesn't provide any way to balance processing. Here is the test code I used
>for both VW and VA:
> ...
>[
> 1 to: processes do: [:i |
>  answers at: i put: 0.
>  [  [loop] whileTrue:
>   answers at: i put: (answers at: i) + 1.
>   Processor yield.
>  ]] fork.
> ].
> ...

The problem isn't with VA's processes. It is with VA optimizing the
to:do: when it shouldn't be. If you change the "1 to: processes do: ...",
to be "(1 to: processes) do: ..." then you'll get the results you expect.
By adding () we can eliminate VA's faulty optimization.

John Brant



Wed, 18 Jun 1902 08:00:00 GMT  
 Balanced process processing


Quote:

> >I'm maintaining test code that attempts to send messages from multiple
> >processes to the same object to ensure concurrency issues are handled
> >properly by semaphores. In doing so, I've observed some differences
between
> >how VisualAge and VisualWorks balance the processing load between
multiple
> >processes of the same priority. VW processing is easily balanced while VA
> >doesn't provide any way to balance processing. Here is the test code I
used
> >for both VW and VA:

> > ...
> >[
> > 1 to: processes do: [:i |
> >  answers at: i put: 0.
> >  [  [loop] whileTrue:

> >   answers at: i put: (answers at: i) + 1.
> >   Processor yield.
> >  ]] fork.
> > ].
> > ...

> The problem isn't with VA's processes. It is with VA optimizing the
> to:do: when it shouldn't be. If you change the "1 to: processes do: ...",
> to be "(1 to: processes) do: ..." then you'll get the results you expect.
> By adding () we can eliminate VA's faulty optimization.

Yes, the parenthesis did the trick. Thanks for the tip. Here are the results
of the three tests on my PC for VA now:

New 10 processes
 results: (0 0 0 0 0 0 0 0 0 9777719)
 total: 9777719.
New 10 processes yielding
 results: (119488 119487 119486 119485 119484 119483 119483 119482 119481
119480)
 total: 1194839.
New 10 processes delaying for 0ms
 results: (52 52 52 52 52 52 52 52 52 52)
 total: 520.

Once you get around the VA optimization problem, VA still performs faster
than VW when yielding. VW has better performance when balancing with Delay,
but at least it shows that VA does give time to other processes when the
active process is delayed. That is a relief.

Knowing when code must be explicitly de-optimized isn't very obvious. I hope
IBM improves this.

Thanks,

Paul Baumann



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to get rid of the NO RECORDS TO PROCESS message on a process

2. when i insert a picture for processing which is 3X3 when processed it is 4x4

3. variable assignment in process or outside of process

4. changing process priority (of an executing process)

5. Inter process communication using Tk/send hangs on suspended processes

6. Q:Forked child processes and mother process

7. Child process on crashing kills it parent process

8. Process to process synchronization (unix)

9. cgi-bin "exec": error waiting for process to exit: No child processes

10. Q: Multiple processes writing to a single process using Expect

11. IPC between C process and Tcl process

12. error waiting for process to exit: No child processes

 

 
Powered by phpBB® Forum Software