Re: Java speed: Reality versus theory?




"Joe Butler" <ffffh.no.spam@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4370da38$0$655$fa0fcedb@xxxxxxxxxxxxxxxxx
[snip]
>> Now what happens if instead of 2 threads, we have 1 billion threads?
> You'll
>> have this pattern:
>>
>> Run A for 0.24 seconds.
>> Switch for 0.01 seconds.
>> Run B for 0.24 seconds.
>> Switch for 0.01 seconds.
>> Run C for 0.24 seconds.
>> Switch for 0.01 seconds.
>> Run D for 0.24 seconds.
>> Switch for 0.01 seconds.
>>
>> It's still 96% of the time doing "useful work", and 4% of the time spent
>> switching threads.
>
> In this situation, the equivalant host OS threading would give a full
> timeslice to each of the threads (let's imagine that it's 10 threads,
> rather
> than a Carl Sagan billion of threads). So, now, each thread gets to run
> for
> a full timeslice before it is switched out - this means that in a single
> round-robin, the 10 OS threads would have recieved 10 time slices from the
> OS, compared to 1 time slice the VM way (that is shared amoungst 10 VM
> threads).

Most OSes give time slices on a per-process basis. That is, if you had
10 OS threads all in the same process, each thread would get 1/10th of the
time slice allocated to their common process, just like the VM.

The reasoning for allocating time slices on a per-process basis instead
of a per-thread basis is to prevent "Denial of Service" attacks on the
kernel by having a process generate a billion thread, and thus get
99.999...% of the CPU time.

- Oliver


.



Relevant Pages

  • Re: Threading questions
    ... is there a DLL equivelent to timeBeginPeriod? ... TimeSlice expires is then much faster of course). ... The time to really switch the context is ...
    (microsoft.public.vb.general.discussion)
  • Re: Threading questions
    ... timeBeginPeriod/timeSetEvent. ... TimeSlice expires is then much faster of course). ... The time to really switch the context is ...
    (microsoft.public.vb.general.discussion)
  • Re: Java speed: Reality versus theory?
    ... Now let's say the VM decides that 0.24 seconds is a good time slice, ... > Switch for 0.01 seconds. ... would give each thread 1 full timeslice before switching to the next thread. ... the equivalant host OS threading would give a full ...
    (comp.programming)