Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
Refactoring Ruby with Monads
31–40 of 41 posts
Re: Refactoring Ruby with Monads
#32Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
>but is apparently normal for pure functional languages Where did you hear that? >and GC pauses longer than 100ms. Yikes! That is not normal at all. You wouldn't be able to write a decent webserver in haskell if that were normal.
Re: Refactoring Ruby with Monads
#33Earlier quoted context omitted.
>but is apparently normal for pure functional languages Where did you hear that? >and GC pauses longer than 100ms. Yikes! That is not normal at all. You wouldn't be able to write a decent webserver in haskell if that were normal.
I think he/she meant the GC pauses were never longer than 100ms.
Re: Refactoring Ruby with Monads
#34Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
The idea is that 90% of allocations are very short-lived, so allocating a ton doesn't matter as long as you can throw it away cheaply. Suppose we have an inner loop over an array, summing values. We may allocate at 1.6 GB/s doing the computation, but everything except the last value is garbage.
When we GC we simply copy this last value from the current heap and reset the "top of heap pointer". Yet another cheap operation.
There's a lot more going on (generational GC, nursery's and what not), but GHC's GC heavily abuse some facts that, for example, CRuby cannot, such as the fact that older generations can never reference data in newer generations, so GCing the current generation never has to perform "major GC" (i.e. checking the older data whether it still needs the current generation).
Re: Refactoring Ruby with Monads
#35Please don't actually do this. Ruby is not a functional language, if your project really needs to be functional all the way through just use Haskell or whatever. Otherwise just pull out the parts of your code would benefit from being expressed in functional style into a module and work on implementing a proper DSL.
Monads are useful even in imperative languages. They're just a context with a way of specifying how actions get chained together. Scala, Swift, and a number of other imperative languages have adopted monads (like Maybe) to great effect. Conversely, the state monad (for example) has seen less adoption. Probably because it's a little difficult to grasp, and imperative languages just rely on mutable state for a similar…
Example of a real monad: http://www.haskell.org/haskellwiki/Monad
Re: Refactoring Ruby with Monads
#36Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
Re: Refactoring Ruby with Monads
#37Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
Small network server? Was it a custom one or one you got from somewhere? I know for a fact that wai, warp, and snap-server are way faster than that.
Re: Refactoring Ruby with Monads
#38Earlier quoted context omitted.
I think he/she meant the GC pauses were never longer than 100ms.
Yes, and getting anywhere close to 100ms is not normal at all. Warp benchmarks show total request latency never goes above 50ms or so, a 100ms gc pause would be very apparent.
Re: Refactoring Ruby with Monads
#39Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
Because, you failed to properly set up GHC, you don't have the right to say anything about Haskell or functional programming.
And I'm sure it's possible to tune GHC. The argument is that if you're going to write immutable data structures in ruby then there is going to be more GC pressure. I don't think it's possible to optimise the ruby GC anywhere near the GHC one because of the mutable nature of the language.
Re: Refactoring Ruby with Monads
#40Recently I benchmarked a small network server written in Haskell. During the load testing the GHC runtime would allocate at rates of 1.6GB/s which is highly unusual from my experience but is apparently normal for pure functional languages. The impressive bit is that during the operations the heap was never bigger than 50MB and GC pauses longer than 100ms. If we where to re-write all our ruby code to be purely functio…
>but is apparently normal for pure functional languages Where did you hear that? >and GC pauses longer than 100ms. Yikes! That is not normal at all. You wouldn't be able to write a decent webserver in haskell if that were normal.
> but is apparently normal for pure functional languages
Where did you hear that?
It's certainly true for Clojure as well. My guess is that it applies to any language that uses immutable data structures. I remember Rich Hickey talking about issues with the JVM due to clojure's unusual allocation model in one of his talks.