[Haskell-cafe] binary IO

Bulat Ziganshin bulatz at HotPOP.com
Tue Dec 27 08:58:26 EST 2005


Hello Joel,

Tuesday, December 27, 2005, 12:18:54 PM, you wrote:

JR> My desired goal is to have 4k bots (threads?) running at the same
JR> time. At, say, 1k/s per bot I figure something like 4Mb/s round-trip.

no problem. my library handle about 10-15mb/s, and i think that speed can
be doubled by using unboxed ints

JR> I'm getting delays of 4s+ with just 100-200 bots reading from a file

divide and conquer! calc speed of networking, unzipping, unpickling
separately. compare these speeds with overall program througput to
calc multithreading "expenses"

JR> and even less than that in a networked environment. The more bots I  
JR> run the higher the delays, to the point of frequent delays of 10s+.

these delays says nothing about speed. you are mixing two things -
your end goal is to make delays short, but your instrument - speeds of
different processes and to decide what you need to optimize you must
calc these speeds separately. without it, your "optimization" is just
random game

JR> Each bot is given 5, 15 or 35 seconds to respond by the poker server

so you don't need to create complex timer thread machinery, just use 3
threads which proceed requests in FIFO order

JR> I spent 3 hard months (barely any weekends, no holidays) polishing my
JR> Haskell code.

... wasting your time to speed up code that is slow by design. don't
forget that this article was published as FUNCTIONAL pearl, not
damn-fast pearl

JR> I started the Erlang rewrite at about 3pm this saturday  
JR> and about 1.5 workdays later I have 80% of what I need. I expect to  
JR> finish the rest today and will have a good yardstick to measure  
JR> Haskell against.

i think that you will get just the same problems as with Haskell and
forced to switch back because it's easier to low-level optimize in
Haskell than in Erlang

JR> My only requirement is that there be a _single_ spec for pickling and
JR> unpickling, i.e. no separate methods. The following is not acceptable  
JR> to me ;-).

say exactly WHY you need this single spec. i know at least 4
solutions, what is the best depends on your exact needs

for example, one of these solutions looks like this:

instance Binary TableInfo where
  put_ bh (TableInfo a b c d) = put_ bh (a,b,c,d)
  get bh = do (a,b,c,d) <- get bh; return (TableInfo a b c d)

instance Binary GameType where
  put_ bh = putWord16 bh . fromEnum
  get = liftM toEnum . getWord16

....

-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Haskell-Cafe mailing list