[Haskell-cafe] Battling time leaks

2005-12-20 Thread Joel Reymont
Folks, It looks like I successfully squashed my time leaks and moving my serialization to Ptr Word8 got me as close to the metal as possible. I'm still getting wierd results, though, and they look like a time leak. ORANGE ALERT: 0s, 6s, SrvServerInfo ORANGE ALERT: 0s, 8s, SrvServerInfo ORAN

[Haskell-cafe] Re: Array performance is killing me

2005-12-20 Thread Joel Reymont
Converting to Ptr Word8 and storables took about an hour and gave me a more favorable profile. COST CENTREMODULE %time %alloc reverse_ Script.Endian 14.4 13.4 sequ Script.Pickle 14.39.3 read

[Haskell-cafe] Haskell trickery

2005-12-20 Thread Joel Reymont
Folks, How is one to interpret the following? I'm particularly interested in the "IO $ \ s -> " notatoin as I have never seen that before. allocaBytes :: Int -> (Ptr a -> IO b) -> IO b allocaBytes (I# size) action = IO $ \ s -> case newPinnedByteArray# size s of { (# s, mbarr# #) ->

[Haskell-cafe] Array performance is killing me

2005-12-19 Thread Joel Reymont
Folks, I managed to reduce my memory consumption but I have a performance problem now. This is a profiling report from my app. -O was not supplied when compiling the library and the relevant modules are at http://wagerlabs.com/array.tgz. COST CENTREMODULE

Re: [Haskell-cafe] Darcs apply error while getting the complete GHC tree

2005-12-17 Thread Joel Reymont
I thought I did :-). I just didn't get to 7.1. My bad and apologies! On Dec 17, 2005, at 7:07 PM, wld wrote: Well, RTBG (Building Guide) ! When building from CVS (I think, from darcs repo too), you should do: autoreconf ./configure -- http://wagerlabs.com/ __

Re: [Haskell-cafe] Darcs apply error while getting the complete GHC tree

2005-12-17 Thread Joel Reymont
I bit the bullet and... did a partial checkout. That worked but now I'm missing a configure file. I did things like this: aclocal autoconf ./configure checking for printf... yes configure: creating ./config.status config.status: creating mk/config.mk config.status: creating mk/config.h config.s

[Haskell-cafe] Darcs apply error while getting the complete GHC tree

2005-12-17 Thread Joel Reymont
I thought I would get the _complete_ ghc tree so that I could build ghc with patches of my own. I decided to get the libraries while I'm at it. I got two errors and don't know what to do now. Do I need to get the whole tree again? Can I somehow reapply the patches that did not get applied?

Re: [Haskell-cafe] Re: Timers

2005-12-17 Thread Joel Reymont
On Dec 15, 2005, at 9:51 PM, Bulat Ziganshin wrote: if half-second precision of performing events is appropriate for you, why don't use solution which holds all events for given second in one list? you can use array of such lists, or map of lists, or even ordered list of lists - it will contain

Re: Re[4]: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-17 Thread Joel Reymont
On Dec 16, 2005, at 1:41 PM, Bulat Ziganshin wrote: JR> I do not have several fixed waiting periods, they are determined by JR> the user. by the user of library? by the poker player? what you exactly mean? By the user of the library. Timers are used imprecisely, to send a timeout event i

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
On Dec 16, 2005, at 3:47 PM, Simon Marlow wrote: Oh, and it looks like you aren't doing -auto-all, that would probably be helpful. Apparently, when you give -p to configure (with Cabal 1.1+) it does add -prof but does not add -auto-all. I added this to my cabal file and my profiling sudden

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
Most of the samples in randomplay.hp look like this: BEGIN_SAMPLE 1.76 (170)Script.Array.CAF 8 (154)Script.CmdType.CAF 64 (165)Script.PickleCmd.CAF 760 (197)Script.PokerClient.CAF 8 (156)Script.Command.CAF 24 (282)Main.CAF 285752 (163)Script.Pickle.CAF 16 (311)/launchScripts#8/laun

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
On Dec 16, 2005, at 3:47 PM, Simon Marlow wrote: I'm a bit mystified though, because looking at the code for Script.Array, all your arrays are unboxed, so I don't know where all the Word8s and Ints are coming from. It might be useful to do "+RTS -hyWord8 -hc" to see who generated the Word8s

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
On Dec 16, 2005, at 3:47 PM, Simon Marlow wrote: Ok, so your heap is mainly full of (a) thunks generated by something in Script.Array, (b) Word8s, and (c) Ints. Would it be worth investigaiting who is holding on to them? interesting... Word8 and Int correspond to the -hd output above, bu

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
On Dec 16, 2005, at 3:47 PM, Simon Marlow wrote: interesting... Word8 and Int correspond to the -hd output above, but '*' indicates that the type of the is polymorphic. Completely polymorphic closures like this are usually (error "something"), which is a silly thing to fill up your heap with

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
Looking at http://wagerlabs.com/randomplay.hd.ps I see closures (constructors?) in this order W8# I# : W16# stg_ap_2_upd_info This tells me it's something having to do with array code. I'm attaching the Script.Array module at the end. This report does not tell me who is retaining the

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
The result of ./randomplay +RTS -p -hd -hclaunchScripts#8 is at http://wagerlabs.com/randomplay.hd.ps Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/has

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
Simon, I'm approaching this methodically, as you are suggesting. I re-ran the program with -hc again and got the following. I suppose it tells me that I need to investigate launchScripts#8. COST CENTREMODULE %time %alloc launchScripts#8Main

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
On Dec 16, 2005, at 12:36 PM, Simon Marlow wrote: If script#9 is the cost center attached to all of your leaking heap data, then you're already a long way to finding the problem. It'll help even more to find out whether it is just unevaluated copies of "takeEmptySeat Holdem affid []", or so

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
I uploaded the full reports to http://wagerlabs.com/randomplay.tgz On Dec 16, 2005, at 11:53 AM, Simon Marlow wrote: What does ordinary heap profiling (-hc, -hd, -hy) tell you about what's in the heap? These options should work fine with STM. -- http://wagerlabs.com/ _

Re: [Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
-hc points to script#9 below. script (_, _, affid) (Custom (JoinedTable 0)) = do {-# SCC "script#8" #-}push "takeEmptySeat" $ {-# SCC "script#9" #-}takeEmptySeat Holdem affid [] {-# SCC "script#10" #-}return $ Eat $ Just Go What takeEmptySeat does it call pickTable takeEm

[Haskell-cafe] Battling laziness

2005-12-16 Thread Joel Reymont
Folks, I have a huge space leak someplace and I suspect this code. The SrvServerInfo data structure is something like 50K compressed or uncompressed byte data before unpickling. My thousands of bots issue this request at least once and I almost run out of memory with 100 bots on a 1Gb mac

[Haskell-cafe] Non-STM bounded queue

2005-12-16 Thread Joel Reymont
Folks, I need to move away from STM (unfortunately) until I profile my program to my satisfaction. Profiling is somewhat crippled with STM in 6.4.1. I cannot do void and drag profiling, for examplel. I decided to abstract my mailboxes in a Queue module so that I could switch between STM a

[Haskell-cafe] +RTS -M800M

2005-12-16 Thread Joel Reymont
Folks, I'm trying to restrict GHC to 800Mb of heap at runtime by passing in +RTS -M800M, the machine has 1Gb of memory and top shows free physical memory dropping below 175Mb. I suppose I'm missing something obvious or paying attention to the wrong statistics, Unix has a good VM manager a

Re: Re[2]: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
Bulat, On Dec 14, 2005, at 9:00 PM, Bulat Ziganshin wrote: TZ> You don't have to check "every few seconds". You can determine TZ> exactly how much you have to sleep - just check the timeout/ event with TZ> the lowest ClockTime. this scenario don't count that we can receive new request while

Re: [Haskell-cafe] Unbound threads and FFI

2005-12-15 Thread Joel Reymont
Simon, I could not find the paper at the link below but it can be found here: http://www.haskell.org/~simonmar/papers/conc-ffi.pdf The paper does not explain the differences I'm seeing between runs of my program linked with the threaded and non-threaded runtimes. I get crashes with the thre

[Haskell-cafe] QuickCheck arbitrary/co-arbitrary

2005-12-15 Thread Joel Reymont
Folks, I'm collecting examples of QuickCheck arbitrary/co-arbitrary definitions, the more complex the better. Please point me to any or send them if you are willing to! Also, is there a cood explanation of co-arbitrary someplace? Thanks, Joel -- http://wagerlabs.com/

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
On Dec 15, 2005, at 2:02 PM, Simon Marlow wrote: Hmm, your machine is spending 50% of its time doing nothing, and the network traffic is very low. I wouldn't expect 2k connections to pose any problem at all, so further investigation is definitely required. With 2k connections the overhead of s

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
On Dec 15, 2005, at 2:02 PM, Simon Marlow wrote: The statistics are phys/VM, CPU usage in % and #packets/transfer speed Total: 1345, Lobby: 1326, Failed: 0, 102/184, 50%, 90/8kb Total: 1395, Lobby: 1367, Failed: 2 Total: 1421, Lobby: 1394, Failed: 4 Total: 1490, Lobby: 146

Re: [Haskell-cafe] Priority queue

2005-12-15 Thread Joel Reymont
I would appreciate it, thank you Ben! Is this the paper? http://www.informatik.uni-bonn.de/ ~ralf/publications/UU-CS-2001-09.pdf On Dec 15, 2005, at 12:26 PM, Benjamin Franksen wrote: I can send you the sources (today, evening, can't access it at work). -- http://wagerlabs.com/ ___

[Haskell-cafe] Re: Timers

2005-12-15 Thread Joel Reymont
Here's the latest and greatest version put together with Einar's help. The seconds portion of ClockTime and a counter are used as the key now and the counter wraps around. This would make two distinct timers even if there expiration times were the same. {-# OPTIONS_GHC -fglasgow-exts -fno-c

[Haskell-cafe] Priority queue

2005-12-15 Thread Joel Reymont
Does anyone have priority queue Haskell code that they would be willing to share or point me to? Thanks, Joel -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell

Re: Timers (was Re: [Haskell-cafe] Optimizing a high-traffic network architecture)

2005-12-15 Thread Joel Reymont
distinguish the timers and avoid clashes. On Dec 15, 2005, at 10:41 AM, Joel Reymont wrote: After a chat with Einar on #haskell I realized that I would have, say, 4k expiring timers and maybe 12k timers that are started and then killed. That would make a 16k element map on which 3/4 of the

Timers (was Re: [Haskell-cafe] Optimizing a high-traffic network architecture)

2005-12-15 Thread Joel Reymont
After a chat with Einar on #haskell I realized that I would have, say, 4k expiring timers and maybe 12k timers that are started and then killed. That would make a 16k element map on which 3/4 of the operations are O(n=16k) (Einar). I need a better abstraction I guess. I also need to be able

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
Here are statistics that I gathered. I'm almost done modifying the program to use 1 timer thread instead of 1 per bot as well as writing to the socket from the writer thread. This should reduce the number of threads from 6k (2k x 3) to 2k plus change. It appears that +RTS -k3k does make a d

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
Something like this. If someone inserts a timer while we are doing our checking we can always catch it on the next iteration of the loop. --- Now runs unblocked checkTimers :: IO () checkTimers = do t <- readMVar timers -- takes it and puts it back case M.size t of -- no tim

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
On Dec 15, 2005, at 12:08 AM, Einar Karttunen wrote: timeout = 500 -- 1 second Is that correct? I think so. threadDelay takes microseconds. Here is a nice trick for you: Thanks! --- The filter expression is kind of long... stopTimer :: String -> IO () stopTimer name = block $

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-15 Thread Joel Reymont
Well, my understanding is that once I do a takeMVar I must do a putMVar under any circumstances. This is why I was blocking checkTimers. On Dec 15, 2005, at 12:08 AM, Einar Karttunen wrote: Is there a reason you need block for checkTimers? What you certainly want to do is ignore exceptions fr

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-14 Thread Joel Reymont
On Dec 14, 2005, at 7:48 PM, Tomasz Zielonka wrote: You don't have to check "every few seconds". You can determine exactly how much you have to sleep - just check the timeout/event with the lowest ClockTime. Something like this? Comments are welcome! It would be cool to not have to export an

Re: [Haskell-cafe] Top-level TVars

2005-12-14 Thread Joel Reymont
On Wed, Dec 14, 2005 at 02:17:17PM -, Simon Marlow wrote: Suppose you create two top-level IORefs with the same type, like this: var1 = unsafePerformIO $ newIORef 0 var2 = unsafePerformIO $ newIORef 0 GHC's CSE optimisation will common these up - after all, it's the same expressi

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-14 Thread Joel Reymont
On Dec 14, 2005, at 7:48 PM, Tomasz Zielonka wrote: You don't have to check "every few seconds". You can determine exactly how much you have to sleep - just check the timeout/event with the lowest ClockTime. Right, thanks for the tip! I would need to way a predefined amount of time when the

Re: [Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-14 Thread Joel Reymont
On Dec 14, 2005, at 6:06 PM, Bulat Ziganshin wrote: as i already said, you can write to socket directly in your worker thread True. 1 less thread to deal with... multiplied by 4,000. you can use just one timeouts thread for all your bots. if this timeout is constant across program run, then

[Haskell-cafe] Optimizing a high-traffic network architecture

2005-12-14 Thread Joel Reymont
Folks, In my current architecture I launch a two threads per socket where the socket reader places results in a TMVar and the socket writer takes input from a TChan. I also have the worker thread the does the bulk of packet processing and a timer thread. The time thread sleeps for a few m

Re: [Haskell-cafe] killThread and FFI calls

2005-12-14 Thread Joel Reymont
On Dec 14, 2005, at 3:22 PM, Simon Marlow wrote: On 14 December 2005 14:26, Joel Reymont wrote: How does killThread work with FFI calls? What happens at the low level when a thread is blocked on an FFI call and received a KillThread exception? Does it exit immediately via some GHC magic or

Re: [Haskell-cafe] Unbound threads and FFI

2005-12-14 Thread Joel Reymont
On Dec 14, 2005, at 3:21 PM, Simon Marlow wrote: this only happens in the -threaded RTS, in the non-threaded RTS a FFI call will block all the other Haskell threads. Just to be absolutely sure... Does the above apply to safe _and_ unsafe FFI? I have been using the non-threaded runtime wit

[Haskell-cafe] Re: GHC internal error: traverse_weak_ptr_list: not WEAK

2005-12-14 Thread Joel Reymont
Forgot to mention that I was profiling at the time. ghc -O --make -threaded -prof -auto-all loadtest.hs -o loadtest -lssl -lcrypto -lz ./loadtest +RTS -hc -sloadtest.gc Cannot compile without -O because of the "extent too large" assembler error. On Dec 14, 2005, at 2:40 PM, Jo

[Haskell-cafe] GHC internal error: traverse_weak_ptr_list: not WEAK

2005-12-14 Thread Joel Reymont
loadtest: internal error: traverse_weak_ptr_list: not WEAK Please report this as a bug to glasgow-haskell-bugs@haskell.org, or http://www.sourceforge.net/projects/ghc/ Has anyone seen this before? I got this after running a 1,300 socket connections for a while (probably x3 threads overa

[Haskell-cafe] Unbound threads and FFI

2005-12-14 Thread Joel Reymont
How do unbound threads play with FFI? According to Simon PJ, each foreign call will get its own OS thread if its blocked. How does GHC determine if the call is blocked? Does each call get its own OS thread from the start? Sometime later? Does this depend on the safe/unsafe specs of the fore

[Haskell-cafe] killThread and FFI calls

2005-12-14 Thread Joel Reymont
Folks, How does killThread work with FFI calls? What happens at the low level when a thread is blocked on an FFI call and received a KillThread exception? Does it exit immediately via some GHC magic or is the exception caught when the FFI call returns? Thanks, Joel -- http://wage

Re: [Haskell-cafe] Top-level TVars

2005-12-14 Thread Joel Reymont
I'm a bit lost in the discussion. Why do I need -fno-cse and how do I seq at the top-level? On Dec 14, 2005, at 10:05 AM, Tomasz Zielonka wrote: On Wed, Dec 14, 2005 at 10:03:42AM -, Simon Marlow wrote: Well sure, but it's only a temporary problem. And you also have to tell them to us

Re: [Haskell-cafe] FreeBSD: Max # of sockets opened

2005-12-13 Thread Joel Reymont
So it's just a matter of recompiling GHC and have it pick up new values? On Dec 13, 2005, at 6:11 PM, Tony Finch wrote: FD_SETSIZE is actually dynamic on FreeBSD (at least from the kernel's point of view - the macros are less so). You can re-set it to whatever value you like at compile time (e.

[Haskell-cafe] Top-level TVars

2005-12-13 Thread Joel Reymont
Can this be done now or is this a GHC 6.5 feature? My combination of unsafePerformIO with atomically $ newTVar does not seem to be working. Thanks, Joel P.S. What is the ETA for 6.5? On Mon, Dec 05, 2005 at 10:50:13AM -, Simon Peyton-Jones wrote: > > It turns out to be e

[Haskell-cafe] FreeBSD: Max # of sockets opened

2005-12-13 Thread Joel Reymont
Folks, I need some help from those of you with a FreeBSD box. It looks like 'ulimit -n' on FreeBSD lets you have 10k+ file descriptors open per process. FD_SETSIZE is 1024 in the system headers, though. GHC relies on this value (see ghc/rts/Select.c). Normally, you will get the EMFILE erro

[Haskell-cafe] Re: [Haskell] ANNOUNCE: Process library (for dataflow-oriented programming?)

2005-12-13 Thread Joel Reymont
Bulat, How is your library licensed? How can a process maintain internal state? How would I use your library to code a socket reader/writer that writes received events to the socket and propagates back anything that is received? The producer/consumer in front of this network client would

Re: Re[2]: [Haskell-cafe] Bringing Erlang to Haskell

2005-12-13 Thread Joel Reymont
Thank you Bulat, makes total sense. This list is a treasure trove of a resource. I guess this is what happens when you go from Erlang to Haskell :-). I'm conditioned to think of everything as a process and uses processes for everything. On Dec 13, 2005, at 11:17 AM, Bulat Ziganshin wrote:

[Haskell-cafe] The Price of Performance

2005-12-13 Thread Joel Reymont
I thought this would be of interest to the Haskell community: http://www.acmqueue.com/modules.php?name=Content&pa=showpage&pid=330 "The ever-growing popularity of small multiprocessors is exposing more programmers to parallel hardware. More tools to spot correctness and performance problems

Re: [Haskell-cafe] Bringing Erlang to Haskell

2005-12-13 Thread Joel Reymont
On Dec 13, 2005, at 9:49 AM, Tomasz Zielonka wrote: On Mon, Dec 12, 2005 at 04:00:46PM +, Joel Reymont wrote: One particular thing that bugs me is that I cannot really use TChan for thread mailboxes. I don't think I experienced this problem with Erlang but using a TChan with a l

Re: Re[2]: [Haskell-cafe] Tricky exception handling

2005-12-13 Thread Joel Reymont
Yes, you are right. I will make the change. On Dec 13, 2005, at 9:28 AM, Bulat Ziganshin wrote: yes, you are muistaken! :) this code will repeat permanently until exception arrived. at this time it will process exception handler and then exit the whole function. you musr reread docs. hmm, actu

Re: [Haskell-cafe] Bringing Erlang to Haskell

2005-12-13 Thread Joel Reymont
On Dec 13, 2005, at 1:13 AM, Bulat Ziganshin wrote: are you read dewscription of my own Process library in haskell maillist? No. Can you give me a pointer? btw, i suggested you to try not using logging thread entirely, making all logging actions synchronously I cannot. Only one thread can

[Haskell-cafe] Safely polymorphic unsafePerformIO

2005-12-12 Thread Joel Reymont
On Dec 12, 2005, at 11:31 AM, Bulat Ziganshin wrote: Hello Joel, this code really looks strange: you asks to create global veriable, but don't say its type :) polymorhism is for functions definitions, any concrete data in Haskell have concrete type It's a long story but I'll try to explain. I

Re: [Haskell-cafe] Tricky exception handling

2005-12-12 Thread Joel Reymont
Bulat, I would welcome suggestions for improvements. Please let me know how my code could be made more efficient and more readable, keeping in mind what I'm trying to accomplish. Notice that my logic is different from the one that you are proposing. What I want is to handle exceptions in t

[Haskell-cafe] Re: Bringing Erlang to Haskell

2005-12-12 Thread Joel Reymont
Just to elaborate a bit... On Dec 12, 2005, at 4:00 PM, Joel Reymont wrote: 1) Processes, aka threads with single-slot in/out mailboxes It's obvious that the thread id and the mailboxes (two TMVar's) would need to be kept together, i.e. a) data Process = ThreadId (TMVar Dynam

[Haskell-cafe] Bringing Erlang to Haskell

2005-12-12 Thread Joel Reymont
Folks, I love the Erlang multi-processing experience and think that a lot of the mistakes that I made could be avoided. What I want to have is 1) Processes, aka threads with single-slot in/out mailboxes 2) A facility to keep a list of such processes and send events to them using their proce

Re: Re[2]: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-12 Thread Joel Reymont
I'm positively not catching the ^C in the main thread. I just went ahead and disabled ^C handling alltogether. On Dec 12, 2005, at 10:50 AM, Bulat Ziganshin wrote: but in 6.4.1 (ATTENTION, JOEL!) this code was breaked. i does an investigation and found that in 6.4.1 with -threaded ^Break hadn

Re: [Haskell-cafe] STM commit hooks

2005-12-12 Thread Joel Reymont
Missed this reply. My bad and apologies to Simon. Einar, did it work for you? On Dec 2, 2005, at 11:15 AM, Simon Marlow wrote: How about this: log_lock <- newTMVar () atomically3 h act = do atomically (do act; takeTMVar log_lock `orElse` abort h) hPrint h Commit atomically (p

Re: [Haskell-cafe] STM commit hooks

2005-12-12 Thread Joel Reymont
I haven't seen a reply on this but would be really interested in one. Simon? On Nov 29, 2005, at 12:39 PM, Einar Karttunen wrote: Hello I have been playing with STM and want to log transactions to disk. Defining a logging function like: log h act = unsafeIOToSTM $ hPrint h act works most th

Re: [Haskell-cafe] STM, orElse and timed read from a channel

2005-12-12 Thread Joel Reymont
If you are talking about the STM one then I saved it for later use. I'm not using timers at all now but it got to the point where I had about 3-5 different implementations stashed away. Yours is one of two remaining, Simon's being the second one :-). On Dec 12, 2005, at 10:09 AM, Tomasz Ziel

Re: [Haskell-cafe] STM, orElse and timed read from a channel

2005-12-12 Thread Joel Reymont
While we are waiting for ghc 6.6, could the same effect be achieved by launching the computation that writes to t with forkIO? On Nov 29, 2005, at 12:00 PM, Simon Marlow wrote: threadDelay is IO-only; there's no way to use threadDelay in an STM transaction. For example, if you want to wait f

[Haskell-cafe] Tricky exception handling

2005-12-12 Thread Joel Reymont
Folks, I have a thread that launches socket reader and writer threads. My intent is to notify the main thread when an exception is caught by the reader/writer. Is this code proper? --- withException :: (Event a -> IO ()) -> IO () -> IO Bool withException po

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-12 Thread Joel Reymont
The app is multi-threaded but uses lightweight threads (unbound). On Dec 12, 2005, at 4:24 AM, Branimir Maksimovic wrote: If your app is single threaded you should be ok. But then nothing is executed concurrently? why locking at all then? You wouldn;t have problems with deadlocks and signals

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-12 Thread Joel Reymont
No way. Thanks for the suggestion, though ;-). On Dec 12, 2005, at 7:48 AM, Tomasz Zielonka wrote: As a fast and dirty solution, I propose using MVar [Dynamic]. -- http://wagerlabs.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org htt

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
My client _is_ single-threaded, I do not use bound (OS) threads at all. Does this shed any light on why my OpenSSL stuff is working as well as my signal handler? ;-) On Dec 12, 2005, at 12:21 AM, Branimir Maksimovic wrote: In single threaded client you can handle ^C if you like in signal

Re: [Haskell-cafe] Tail-call optimization

2005-12-11 Thread Joel Reymont
Thank you Andrew! Does it have any effect on performance? Is there a speed up of any sort from not passing parameters? On Dec 11, 2005, at 11:50 PM, [EMAIL PROTECTED] wrote: Good, but even better is this: writeLoop :: (Event a -> IO ()) -> Handle -> (SSL, BIO, BIO) -> IO () writeLoop post h

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
On Dec 11, 2005, at 10:02 PM, Branimir Maksimovic wrote: Problem with mt programs is that they just appear to work but in havy load situation those errors show once a while. My loads are pretty heavy. Did not see any problems with SSL yet. This should be enough reason to scan for keyboar

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
^C seems to be '\ETX' so ignoring SIGINT and using getChar should probably do it. On Dec 11, 2005, at 11:31 PM, Joel Reymont wrote: Allright, I _am_ convinced. How do I ready ^C from the keyboard??? On Dec 11, 2005, at 10:02 PM, Branimir Maksimovic wrote: This should be enough

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Allright, I _am_ convinced. How do I ready ^C from the keyboard??? On Dec 11, 2005, at 10:02 PM, Branimir Maksimovic wrote: This should be enough reason to scan for keyboard events instead. There is no guarantee that SIGINT would be sent only by keyboard. -- http://wagerlabs.com/ __

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Oh, right. It does not apply in my case, though, so I thought it was safe. I'm not sure what the proper Haskell wording is to explain but it seems like the type system catches if a user of the library tries to use two different a's (Child a) and complains. Exactly what I need as access to

Re: [Haskell-cafe] syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
On Dec 11, 2005, at 8:35 PM, Donn Cave wrote: Now if you actually have observed that your SIGINT handler was entered at this point, then please ignore me. Yes, I have observed my SIGINT handler being triggered out of nowhere. Since I'm printing the signal# in the handler I actually know that

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Would you care to elaborate? This has not caused any problems for me so far but this is probably due to my usage. On Dec 11, 2005, at 8:09 PM, Tomasz Zielonka wrote: On Sun, Dec 11, 2005 at 07:09:20PM +, Joel Reymont wrote: {-# NOINLINE children #-} children :: MVar [Child a] children

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
What I do works so I don't see any reason to do it otherwise. Now, it might work by luck and chance, by some ghc magic or otherwise, but it does work and causes me no problems. Not when I press ^C and everything shuts down cleanly. My issues are 1) A phantom sigINT that gets sent to me out of no

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Understood. But I'm printing things in the signal handler to show that it was triggered. And I trigger it when ^C is pressed (well, one more signal): initSnippets :: IO () initSnippets = do initSSL installHandler sigPIPE Ignore Nothing flip mapM_ [sigTERM, sigINT] $ \sig ->

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
ng on that. On Dec 11, 2005, at 5:12 PM, Peter Simons wrote: Joel Reymont writes: How do I get a threaded+debug runtime? You have to build GHC from source code for that. When you do, make sure your ${srcdir}/ghc/mk/build.mk file contains: GhcRTSWays += thr_debug --

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
The second one is the threaded and profiled runtime. On Dec 11, 2005, at 5:14 PM, Branimir Maksimovic wrote: I've got two versions: HSrts_thr and HSrts_thr_p I don't know what's second for? but there is only one with debug in it's name. So I'm not much of a help here. -- http://wagerlabs.com/

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Nothing like answering your own questions... There's no deadlock information for the threaded version of the runtime so I would not have deadlock information if I were to compile with -threaded. On Dec 11, 2005, at 5:00 PM, Joel Reymont wrote: Linking ... /usr/bin/ld: can't l

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Linking ... /usr/bin/ld: can't locate file for: -lHSrts_thr_debug collect2: ld returned 1 exit status How do I get a threaded+debug runtime? On Dec 11, 2005, at 4:50 PM, Branimir Maksimovic wrote: Strange is that you are using threaded run time (I guess ) but this function is defined only for

Re: [Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
On Dec 11, 2005, at 4:50 PM, Branimir Maksimovic wrote: This is not signal, it is result from call to pause() . [...] you have to look elsewhere as this is normal behavior. You are saying that triggering my ^C handler randomly is normal behavior? I understand why it goes to wait for signals

[Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
I looked at the scheduler source code and it appears that GHC goes to wait for signals when a deadlock is detected and there's nothing else to do. It still does not explain where the signal comes from when I'm away from the keyboard. On Dec 11, 2005, at 4:10 PM, Joel Rey

[Haskell-cafe] syscall, sigpause and EINTR on Mac OSX

2005-12-11 Thread Joel Reymont
Folks, I'm kind of stuck on this and can't figure it out... Take a look at the trace below, this is Mac OSX Tiger. (gdb) where #0 0x90006068 in syscall () #1 0x9004420c in sigpause () #2 0x001791b8 in awaitUserSignals () at Signals.c:256 #3 0x0012e1a8 in schedule (mainThread=0x1300360, in

Re: Re[2]: [Haskell-cafe] [Newbie] Why or why not haskell ?

2005-12-11 Thread Joel Reymont
I would surmise that speed is not always the point. This is what's usually used to defend the laziness of Haskell :-). Erlang is _the_ language for network programming, trust me on this one. My dreamhost site seems to be down at the moment but you can poke around the Erlang category at http

Re: [Haskell-cafe] [Newbie] Why or why not haskell ?

2005-12-10 Thread Joel Reymont
Erlang can be compiled to machine code with the built-in HiPE compiler. You just have to explicitly make use of this facility. On Dec 10, 2005, at 11:25 PM, Bulat Ziganshin wrote: what you mean saying "network programming"? Erlang has amazing distributed processing features with fault tolerance

[Haskell-cafe] Tail-call optimization

2005-12-10 Thread Joel Reymont
I always wandered, does ghc do tail-call optimization? Would it optimize the two variants of the function below or just the first one? --- Proper? writeLoop :: (Event a -> IO ()) -> Handle -> (SSL, BIO, BIO) -> IO () writeLoop post h ssl = do handle (\e -> post $ NetworkError e) $

[Haskell-cafe] Strictness that GHC infers for functions

2005-12-09 Thread Joel Reymont
Duncan, How do you find out the strictness that ghc infers for functions? Thanks, Joel On Dec 8, 2005, at 8:09 PM, Duncan Coutts wrote: For example it's not currently convenient to find out the strictness that ghc infers for functions (though it is possible). Ideally an IDE or some

[Haskell-cafe] Indenting issue with Haskell mode

2005-12-08 Thread Joel Reymont
I believe the following is not indented correctly. It only happens with (x:xs) when you use nested cases, I think. case foo of [] -> case bar of [] -> return () (x:xs) -> -- http://wagerlabs.com/ ___ Haskell-Cafe mail

Re: Re[2]: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
Doesn't this have an effect on performance? Is GHC still able to optimize things properly? On Dec 8, 2005, at 10:20 AM, Bulat Ziganshin wrote: Hello Joel, Thursday, December 08, 2005, 12:26:52 PM, you wrote: JR> I was also hoping that something like this would let me avoid JR> quantifying a

Re: [Haskell-cafe] Mixing C++ and Haskell, OpenSSL thread safety, and using mmap

2005-12-08 Thread Joel Reymont
I only lock around the connectTo to avoid the gethostbyname issue. After that I set up two memory BIOs and hook them to go through a handshake. Encryption is done through the BIOs afterwards since I need to wrap the encrypted data in a header of my own (don't ask). I haven't had a problem w

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
Here is something else that I don't quite understand... Original version compiles: push :: Show b => State b -> Dispatcher b a -> (ScriptState a b) () push state dispatcher = do w <- get trace 95 $ "push: Pushing " ++ show state ++ " onto the stack" let s = stack w putSt

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
I was also hoping that something like this would let me avoid quantifying a in functions downstream but alas, it does not happen. I have to use (Eq a, Show a) => a ... everywhere else. On Dec 7, 2005, at 11:14 PM, Bulat Ziganshin wrote: data (Show a, Eq a) => State a = Start | Sto

Re: [Haskell-cafe] Mixing C++ and Haskell, OpenSSL thread safety, and using mmap

2005-12-08 Thread Joel Reymont
I use OpenSSL in a heavily threaded environment. It works without extra locking. I do not use bound (OS) threads, though. On Dec 8, 2005, at 7:06 AM, Branimir Maksimovic wrote: First I want to say about OpenSSL thread safety. It is not thread safe by default. Who wants to import and use Open

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
On Dec 8, 2005, at 12:09 AM, John Meacham wrote: if you are okay with a being an argument then data State a = Start | Stop | State a deriving(Show,Eq) will do what you want I believe. This does the trick! Thank you! -- http://wagerlabs.com/

Re: [Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-08 Thread Joel Reymont
Did someone actually try compiling this? Here are the results: data State a = Start | Stop | (Show a, Eq a) => State a deriving Show foo.hs:1:5: Can't make a derived instance of `Show (State a)' (`State' has existentially-quantified constructor(s)) When deriving insta

[Haskell-cafe] Existentially-quantified constructors, Eq and Show

2005-12-07 Thread Joel Reymont
Folks, Is there a less verbose way of doing this: data State a = Start | Stop | (Show a, Eq a) => State a instance Eq a => Eq (State a) where (State a) == (State b) = a == b Start == Start = True Stop == Stop = True instance Show a => Show (State a) where show (Stat

<    1   2   3   4   5   >