[racket] Problems trying to do non-blocking I/O and a reactor loop

From: Greg Hendershott (greghendershott at gmail.com)
Date: Fri Aug 3 20:51:37 EDT 2012

The results so far:

1. Bad news: The reqs/sec seem much lower than before. i.e. Does the
bug fix have a performance hit?

2. Good news: The "input port closed" error seemed to be gone with
5.3.0.16. Except ...

3. Bad news: I just got it to happen again, with 5.3.0.16:

$ /Applications/Racket_v5.3.0.16/bin/racket bug-example.rkt
serve: port=8081 hostname=#f timeout=60
peek-bytes-avail!: input port is closed
  context...:
   /Applications/Racket_v5.3.0.16/collects/racket/port.rkt:1114:4: try-again

This after doing `ab' runs like this:

$ ab -n 10000 -c 5 http://localhost:8081/

The thing is, I did about 10 such runs of `ab' -- with the same
"server" running the whole time. In other words, the likelihood of the
error happening seems to grow the longer the server runs. It _seems_
to happen _later_ with 5.3.0.16 than with 5.2.1. OTOH with this sort
of issue I suppose that could be "random".


I wonder can anyone else elicit these problems trying to run it, too?

As I've done little with `sync' and events in Racket to-date, I'm
half-wondering if the issue is me being muddled. So if anyone wants to
code-review me, I'd welcome the critique, too.

Thanks again.

On Fri, Aug 3, 2012 at 8:36 PM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> Thank you for such a quick reply!
>
>> I see that you're using `read-bytes-avail!-evt', which has problems in
>> v5.2.1 that are fixed for v5.3. The problems include triggering a bug
>> in `sync', which is also fixed for v5.3.
>
> Well, I only tried read-bytes-avail!-evt after getting similar errors
> with regexp-match-evt.  So if the fix is specific to rba-evt, that's
> probably not it.
>
> Also although it was maybe buried in the comments, I had the same
> errors with 5.2 as 5.2.1. FWIW.
>
>> Does a nightly build behave any differently?
>
> I'm trying 5.3.0.16 right now. ApacheBench is not eliciting the errors
> ... so far. Previously it could take awhile before the errors would
> start to pop up.  Fingers crossed ...
>
> On Fri, Aug 3, 2012 at 7:56 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
>> I see that you're using `read-bytes-avail!-evt', which has problems in
>> v5.2.1 that are fixed for v5.3. The problems include triggering a bug
>> in `sync', which is also fixed for v5.3.
>>
>> Does a nightly build behave any differently?
>>
>> At Fri, 3 Aug 2012 19:11:44 -0400, Greg Hendershott wrote:
>>> Even the distilled code is maybe a wee bit long for here, so I made a gist:
>>> https://gist.github.com/3252353
>>>
>>> I wanted to try doing non-blocking I/O and a reactor event loop.
>>>
>>> The gist is an excerpt to simplify the problem case. What I left out
>>> is the fun stuff where Racket could make this less painful, such as
>>> using continuations or simply generators to avoid
>>> nested-callback-chain heck. But before the fun stuff, the foundation:
>>>
>>> Under a light load everything works fine. But ApacheBench with -c > 2
>>> is making it unhappy, as described in the comments.
>>>
>>> Sometimes it will blow through 10,000 reqs at -c 20 with no problem.
>>> And giving at least 2X better reqs/sec than comparable
>>> thread-per-connection example. Yay!
>>>
>>> But on most runs it's getting errors with "input port closed".  And
>>> rarely I will get a channel? from sync when it should only be an
>>> eof-object? or integer.  And rarely I even get a Racket seg fault.
>>> Boo!
>>>
>>> So. Probably I'm doing one or more really stupid things?  Any advice
>>> would be welcome -- thank you!
>>> ____________________
>>>   Racket Users list:
>>>   http://lists.racket-lang.org/users

Posted on the users mailing list.