Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Parallelism? (Edward Z. Yang)
   2. Re:  Parallelism? (Felipe Almeida Lessa)
   3. Re:  Parallelism? (Michael Craig)
   4. Re:  Parallelism? (Edward Z. Yang)
   5.  discover data constructor without pattern        matching?
      (Philippe Sismondi)
   6. Re:  discover data constructor without pattern    matching?
      (Ozgur Akgun)
   7. Re:  Parallelism? (Michael Craig)


----------------------------------------------------------------------

Message: 1
Date: Thu, 01 Dec 2011 11:40:17 -0500
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Parallelism?
To: Michael Craig <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1322757211-sup-6303@ezyang>
Content-Type: text/plain; charset=UTF-8

Simon Marlow investigated, and we got this patch out:

commit 6d18141d880d55958c3392f6a7ae621dc33ee5c1
Author: Simon Marlow <[email protected]>
Date:   Thu Dec 1 10:53:28 2011 +0000

    Fix a scheduling bug in the threaded RTS

    The parallel GC was using setContextSwitches() to stop all the other
    threads, which sets the context_switch flag on every Capability.  That
    had the side effect of causing every Capability to also switch
    threads, and since GCs can be much more frequent than context
    switches, this increased the context switch frequency.  When context
    switches are expensive (because the switch is between two bound
    threads or a bound and unbound thread), the difference is quite
    noticeable.

    The fix is to have a separate flag to indicate that a Capability
    should stop and return to the scheduler, but not switch threads.  I've
    called this the "interrupt" flag.

Thanks for constructing this lovely test-case!

Cheers,
Edward

P.S. When you run in single-threaded runtime, the second thread never
actually finishes. You need to manually wait on it for an MVar.
Also, note that putStrLn is synchronized by an MVar, to avoid interleaved
output.

Excerpts from Michael Craig's message of Thu Dec 01 00:50:15 -0500 2011:
> I was writing some parallel code (asynchronous database writes for an event
> logger, but that's besides the point), and it seemed like the parallelized
> version (i.e. compiled with -threaded -with-rtsopts=-N2) wasn't running
> fast enough. I boiled it down to a dead-simple test:
> 
>     import Control.Concurrent
>     import Data.Time.Clock.POSIX
>     import System.Environment
> 
>     main :: IO ()
>     main = do
>         n <- getArgs >>= return . read . head
>         t1 <- getPOSIXTime
>         work n
>         t2 <- getPOSIXTime
>         putStrLn $ show $ t2 - t1
>         putStrLn $ show $ (fromIntegral n :: Double)
>                         / (fromRational . toRational $ t2 - t1)
> 
>     work :: Integer -> IO ()
>     work n = do
>       forkIO $ putStrLn $ seq (fact n) "Done"
>       putStrLn $ seq (fact n) "Done"
> 
>     fact :: Integer -> Integer
>     fact 1 = 1
>     fact n = n * fact (n - 1)
> 
> (I know this is not the best way to time things but I think it suffices for
> this test.)
> 
> Compiled with ghc --make -O3 test.hs, ./test 500000 runs for 74 seconds.
> Compiling with ghc --make -O3 -threaded -with-rtsopts=-N, ./test 500000
> runs for 82 seconds (and seems to be using 2 cpu cores instead of just 1,
> on a 4-core machine). What gives?
> 
> Mike S Craig



------------------------------

Message: 2
Date: Thu, 1 Dec 2011 15:10:58 -0200
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Parallelism?
To: "Edward Z. Yang" <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <CANd=OGG7Y0N6dJFrMF6bQ3s9_RCQWwsSAbS_+kc2GZ=oQ2B0=a...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Thu, Dec 1, 2011 at 2:40 PM, Edward Z. Yang <[email protected]> wrote:
> Simon Marlow investigated, and we got this patch out:

Nice work, guys!  Hope it gets included in the glourious GHC 7.4 =D.

Cheers,

-- 
Felipe.



------------------------------

Message: 3
Date: Thu, 1 Dec 2011 13:17:57 -0500
From: Michael Craig <[email protected]>
Subject: Re: [Haskell-beginners] Parallelism?
To: Felipe Almeida Lessa <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <caha9zaebcynttupswvlpfjj_nbpjzo1ijzccnu_rt32pxl7...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Excellent! Glad this has been sorted out upstream.

Edward, to answer your question regarding blocking database calls: I'm
using mongoDB to log events that come into a WAI webapp. The writes to
mongo are blocking, so I'd like to run them in parallel with the webapp.
The webapp would push the data into a Chan and the mongo writer would read
from the Chan and make the writes sequentially (using the Chan as a FIFO
between parallel threads). This would allow for request rates to
temporarily rise above mongo's write rate (of course with an expanded
memory footprint during those bursts).

Mike S Craig


On Thu, Dec 1, 2011 at 12:10 PM, Felipe Almeida Lessa <
[email protected]> wrote:

> On Thu, Dec 1, 2011 at 2:40 PM, Edward Z. Yang <[email protected]> wrote:
> > Simon Marlow investigated, and we got this patch out:
>
> Nice work, guys!  Hope it gets included in the glourious GHC 7.4 =D.
>
> Cheers,
>
> --
> Felipe.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111201/caa14408/attachment-0001.htm>

------------------------------

Message: 4
Date: Thu, 01 Dec 2011 14:38:44 -0500
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Parallelism?
To: Michael Craig <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1322768284-sup-9706@ezyang>
Content-Type: text/plain; charset=UTF-8

OK. A common mistake when using channels is forgetting to make sure
all of the informaiton is fully evaluated in the worker thread, which then
causes the writer thread to spend all its time evaluating thunks.

Edward

Excerpts from Michael Craig's message of Thu Dec 01 13:17:57 -0500 2011:
> Excellent! Glad this has been sorted out upstream.
> 
> Edward, to answer your question regarding blocking database calls: I'm
> using mongoDB to log events that come into a WAI webapp. The writes to
> mongo are blocking, so I'd like to run them in parallel with the webapp.
> The webapp would push the data into a Chan and the mongo writer would read
> from the Chan and make the writes sequentially (using the Chan as a FIFO
> between parallel threads). This would allow for request rates to
> temporarily rise above mongo's write rate (of course with an expanded
> memory footprint during those bursts).
> 
> Mike S Craig
> 
> 
> On Thu, Dec 1, 2011 at 12:10 PM, Felipe Almeida Lessa <
> [email protected]> wrote:
> 
> > On Thu, Dec 1, 2011 at 2:40 PM, Edward Z. Yang <[email protected]> wrote:
> > > Simon Marlow investigated, and we got this patch out:
> >
> > Nice work, guys!  Hope it gets included in the glourious GHC 7.4 =D.
> >
> > Cheers,
> >
> > --
> > Felipe.
> >



------------------------------

Message: 5
Date: Thu, 1 Dec 2011 17:38:05 -0500
From: Philippe Sismondi <[email protected]>
Subject: [Haskell-beginners] discover data constructor without pattern
        matching?
To: Beginners Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Is it possible to discover the data constructor used to make a value without 
doing pattern matching?

In my current small project I have a data type with a zillion constructors. 
These use record syntax so that I can access the payload without pattern 
matching. But I just discovered that it I want to print out the constructor 
name in my error handling function. Can I do this without, say, hacking around 
with a string from 'show'?

- P -


------------------------------

Message: 6
Date: Thu, 1 Dec 2011 22:47:07 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] discover data constructor without
        pattern matching?
To: Philippe Sismondi <[email protected]>
Cc: Beginners Haskell <[email protected]>
Message-ID:
        <calzazpcxia_7yayzf75sa3ehqw4ky6zcvr17ieyr-zmmaya...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

On 1 December 2011 22:38, Philippe Sismondi <[email protected]> wrote:

> Is it possible to discover the data constructor used to make a value
> without doing pattern matching?


Yes, it is.

constrName :: Data a => a -> String
constrName = show . toConstr

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Data.html#v:toConstr

(You can derive *Data* for your data type using the language extension *
DeriveDataTypeable*)

Hope this helps,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111201/2e2c692e/attachment-0001.htm>

------------------------------

Message: 7
Date: Thu, 1 Dec 2011 19:08:32 -0500
From: Michael Craig <[email protected]>
Subject: Re: [Haskell-beginners] Parallelism?
To: "Edward Z. Yang" <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <caha9zahejpfw+ruudhjve2dztoy6sqv7z-h-vor6dkfuubf...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Thanks, I'll keep that in mind.

I wrote a better example of what I'm trying to do:
https://gist.github.com/1420742 It runs worse with multiple threads than it
does with one (both time-wise and memory-wise), I think due to the bug
Simon described in that commit.

But that bug aside, is it possible to write a multithreaded application in
Haskell that sends large amounts of data from one thread to the other
without getting crushed by GC? I've looked into the garbage collector a
bit, and this seems problematic.

Mike S Craig


On Thu, Dec 1, 2011 at 2:38 PM, Edward Z. Yang <[email protected]> wrote:

> OK. A common mistake when using channels is forgetting to make sure
> all of the informaiton is fully evaluated in the worker thread, which then
> causes the writer thread to spend all its time evaluating thunks.
>
> Edward
>
> Excerpts from Michael Craig's message of Thu Dec 01 13:17:57 -0500 2011:
> > Excellent! Glad this has been sorted out upstream.
> >
> > Edward, to answer your question regarding blocking database calls: I'm
> > using mongoDB to log events that come into a WAI webapp. The writes to
> > mongo are blocking, so I'd like to run them in parallel with the webapp.
> > The webapp would push the data into a Chan and the mongo writer would
> read
> > from the Chan and make the writes sequentially (using the Chan as a FIFO
> > between parallel threads). This would allow for request rates to
> > temporarily rise above mongo's write rate (of course with an expanded
> > memory footprint during those bursts).
> >
> > Mike S Craig
> >
> >
> > On Thu, Dec 1, 2011 at 12:10 PM, Felipe Almeida Lessa <
> > [email protected]> wrote:
> >
> > > On Thu, Dec 1, 2011 at 2:40 PM, Edward Z. Yang <[email protected]> wrote:
> > > > Simon Marlow investigated, and we got this patch out:
> > >
> > > Nice work, guys!  Hope it gets included in the glourious GHC 7.4 =D.
> > >
> > > Cheers,
> > >
> > > --
> > > Felipe.
> > >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111201/753170c4/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 42, Issue 2
****************************************

Reply via email to