[racket] Thread creation slow?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Aug 10 12:30:01 EDT 2012

Yes, I see some O(N) behavior for N threads on each GC, and I'm trying
to fix it.

At Fri, 10 Aug 2012 12:23:44 -0400, Sam Tobin-Hochstadt wrote:
> Using my gcstats library, I get the following info.  GC is about 75%
> of the total runtime, which surprises me since there should be no
> garbage until all the channels are set up, which takes most of the
> time. Note the extremely large amount of slop space.
> 
>     305,562,856 bytes allocated in the heap
>     304,922,088 bytes collected by GC
>   1,755,839,256 bytes max heap size
>     975,524,384 bytes max slop
>   2,722,820,096 bytes peak total memory use
> 
> Generation 0:      64 collections,   25,581ms, 25,635.9ms elapsed
> Generation 1:       6 collections,    4,980ms, 4,982.54ms elapsed
> 
> INIT  time        12 ms
> MUT   time     9,461 ms (  9,456.13 ms elapsed)
> GC    time    30,561 ms ( 30,618.52 ms elapsed)
> TOTAL time    40,034 ms ( 40,086.65 ms elapsed)
> 
> %GC time       76.36%   ( 76.40% elapsed)
> 
> Alloc rate     32,297,099 bytes per MUT second
> 
> for this slightly modified version:
> 
> #lang racket/base
> 
> (define leftmost (make-channel))
> (define (setup-whispers left i n)
>   (if (>= i n)
>       left
>       (let ((right (make-channel)))
>         (thread (lambda ()
>                   (channel-put left (+ 1 (channel-get right)))))
>         (setup-whispers right (+ 1 i) n))))
> (define rightmost (setup-whispers leftmost 0 100000))
> 
> (thread (lambda () (channel-put rightmost 1)))
> (channel-get leftmost)
> 
> 
> On Fri, Aug 10, 2012 at 12:11 PM, Eric Dobson <eric.n.dobson at gmail.com> wrote:
> > When I played around with it, I remember that the issue was that
> > threads created a lot of garbage, and made collecting garbage slow.  I
> > could create about 400 times as many boxes in a chain and get the same
> > gc time.
> >
> > This lead to a quadratic(ish) runtime for creating a bunch of threads,
> > as each later GC took more time.
> >
> >
> > On Fri, Aug 10, 2012 at 8:51 AM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:
> >> Hi all,
> >>
> >> On IRC the other day, this blog article about Racket came up:
> >>   http://cxwangyi.wordpress.com/2012/07/29/chinese-whispers-in-racket-and-go/
> >>
> >> In it, the author shows a program that creates many threads & channels
> >> and then daisy-chains some communication through them. The Racket
> >> version is significantly slower than the Go version (1 min. vs. 1 sec.).
> >>
> >> Is there a performance bug with thread creation here? Alternatively, is
> >> there a different way of coding the example that would make it faster?
> >>
> >> Cheers,
> >> Asumu
> >> ____________________
> >>   Racket Users list:
> >>   http://lists.racket-lang.org/users
> > ____________________
> >   Racket Users list:
> >   http://lists.racket-lang.org/users
> 
> 
> 
> -- 
> sam th
> samth at ccs.neu.edu
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.