[gambit-list] thread-send performance issue?
Marc Feeley
feeley at iro.umontreal.ca
Thu Jan 22 16:49:31 EST 2009
The reason is simply that you have other threads running at that point
and this slows down the code executed by (time ...). The runtime
system does not maintain run times on individual threads. There is
just one global clock. I once considered maintaining run times on
individual threads but it would be a very large overhead for threads
that do very little computation between context switching (because
getting the current-time from the operating system can be expensive, I
have seen 1 microsecond, which would double the execution time of a
thread which runs every microsecond, like the ring benchmark).
Marc
On 22-Jan-09, at 3:49 PM, David St-Hilaire wrote:
> Hi all!
>
> I'm facing a weird situation... I tracked down in a program of mine
> a bottleneck
> which came up to be a call to thread-send. After addint a (time ...)
> around it I
> found that it takes around ~20 ms to perform the thread send (which
> I believe is
> pretty slow):
>
> (time (thread-send user-interface-thread `(redraw ,level)))
> 24 ms real time
> 20 ms cpu time (10 user, 10 system)
> 1 collection accounting for 2 ms real time (0 user, 0 system)
> 40536 bytes allocated
> no minor faults
> no major faults
> (time (thread-send user-interface-thread `(redraw ,level)))
> 18 ms real time
> 10 ms cpu time (10 user, 0 system)
> no collections
> 37900 bytes allocated
> no minor faults
> no major faults
>
> I'd like to note here that level in the code sample above is a
> rather big data
> structure, but I believe this is irrelevant because only the pointer
> should be
> passed down?
>
> Strangely, I tried to reproduced the behaviour in a repl but I only
> happened to
> get ~0ms for these thread-send calls:
>
>> (define t (make-thread (lambda () (let loop () (pp (thread-
>> receive)) (loop)))))
>> (thread-start! t)
> #<thread #2>
>> (time (thread-send t 'allo))
> (time (thread-send t 'allo))
> 0 ms real time
> 0 ms cpu time (0 user, 0 system)
> no collections
> 24 bytes allocated
> no minor faults
> no major faults
>> allo
> (time (thread-send t 'allo))
> (time (thread-send t 'allo))
> 0 ms real time
> 0 ms cpu time (0 user, 0 system)
> no collections
> 24 bytes allocated
> no minor faults
> no major faults
>> allo
>
> Thank you very much for your help!
>
> David
>
>
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
More information about the Gambit-list
mailing list