The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Dealing with Network IO timeouts

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Dealing with Network IO timeouts Posted: Oct 5, 2005 5:10 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Dealing with Network IO timeouts
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

It was time I did another Extra package. And I got an opportunity to.

Any real network programming requires that you deal with the network IO timeout problem. In C code, this basically means that you preface any read()/write()/send()/recv() with a poll()/select() call that has a non-zero timeout, and take appropriate action when your timeout expires.

In VisualWorks Smalltalk, this is not immediately obvious though, because we bury our IOAccessor objects (the equivalent of a C file descriptor) behind ExternalStreams, and Constructor (eww) thingies, and IOPositionableBuffers. For the most part this is a good thing. You get to use the same powerful streaming features on a socket that you would for a file, or an internal string, or whatever. But the timeout thing, it makes it tricky.

Our first attempt at this was to use a sort of a "transactional" timeout. Specify the time you expect to send your command, have it processed, and read the ack back. Many eons ago, I blogged about Finished Yet?, an extension to BlockClosure, so you could time them out. It was actually built originally for just this problem, though I've found it generally useful for other things too.

That worked fine for us for a while. It worked because it was run from a UI, and UIs don't normally do much. Other than interact asynchronously in short bursts. But then I added some monitoring processes which did long running computations, at a priority higher than some of the networking polling threads. Suddenly I started having timeout problems. Not because I was having legitimate network IO problems, but because I was starving the transactions from ever getting any work done. I tried a variant of the transaction timeout, that attempted to let the process run if it could as long as it wasn't idle after the timeout. This didn't really fix it.

SocketAccessor has the ability to do a select()/poll(), it's just not wired into the normal methods that streams and such use. Time for a new approach. Make timeout a first class part of SocketAccessor, rather than layering it on with other techniques.

ExtraSockets does this by adding a readTimeout and writeTimeout. By default, they are nil, and any methods which might use them, do the original thing. But if they're not nil, the two subclass overridden methods (readInto:startingAt:for: and writeFrom:startingAt:for:), first do the equivalent of the select(). And if they fail, raise a SocketIOTimeout (maybe we should have reused one of the existing signals, if you have suggestions let me know).

Results so far? Great. It works better than the old framework. With or without the longrunnning computations. And it made putting the timeout parameters much easier. Basically, the socket is given a read/write timeout that is indicative of what worst case network latencies are. The query proceeds. A transaction specific readWait is entered to allow the end processing time to vary per transaction. And then normal read timeouts apply for actually reading back the response.

I'm pretty convinced that network io timeouts are not something that should be "layered" on top of sockets. They should be first class integral parts of them. I'd love to see this code/approach integrated into VisualWorks in one way or another. Until then, feel free to grab ExtraSockets and see if it doesn't make your network IO timeout code easier and more robust.

Read: Dealing with Network IO timeouts

Topic: Serenity Previous Topic   Next Topic Topic: Weekly Log Analysis: October 1, 2005

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use