Hacker News new | ask | show | jobs
by jzoidberg 5396 days ago
Akka actors are the accepted production solution in Scala.

I wonder how the author translated actor heavy code to clojure - I guess the closest available concept would be agents.

1 comments

The original Scala code was written back in November 2009. Akka wasn't really the "accepted production solution" back then. There's no question that it is _today_.

We used actors to create a pool of workers in order to run some slow processes in parallel. The simplest equivalent in Clojure was to run the processes via pmap. Cheap, quick and very effective. We didn't have as much control over the parallelism but it didn't really matter for our use case.

We had about 1,000 lines of Scala that we'd developed as we learned Scala. Today we have more experience in Clojure than we did in Scala back then. Writing 260 lines of Clojure with the Scala code as a guide took a couple of days, including writing a new set of unit tests.

Learning enough about Akka to migrate to it would have taken us some time - and would still have left us with three languages in the mix. By replacing this Scala code with Clojure, we only had two languages in the mix, which was also a win.

I'm surprised that you chose to use actors to parallelize your code. I always thought they were more valuable for concurrency. Back before Scala 2.8 came out with parallel collections, when I need parallelism I wrote my own pmap-like functions. It was really easy, probably easier than learning the whole concept of actors, let alone an implementation of them, and I got the performance speedup I was looking for.

It sounds to me like you got a large code reduction because in Scala you used a heavyweight concurrency solution to a lightweight parallelism problem.

I just went back and looked at the code overhead of using actors over what it might look like with 2.9's parallel collections and the difference would be about 25-30 lines so I don't think that counts as a potentially "large code reduction". Wrapping three bits of code in actors doesn't add much ceremony (which is in fact a great example of how concise Scala can be when adding concurrency!).

(And parallel collections came in 2.9, not 2.8 - we'd already migrated, painfully, from 2.7 to 2.8)

[edit: See my comment below on how this might be a culture thing]

I wonder how 15 hours in the post become a couple of days here on HN. But of course, the post was written as an anecdote and should be taken as that.

Could you elaborate what makes Akka "a language" for you? I did assume Akka actors are for all practical reasons a drop in replacement for scala actors.

More people should btw. read "Anecdotal Evidence and Other Fairy Tales" in Hacknots book:

http://www.scribd.com/doc/459372/hacknot-book-a4

15 hours = 2 x 7.5 hours - 2 days? (seems like basic math to me :)

Akka is _not_ a language - I'm not sure where you got that impression? (please explain so I can respond to it - no judgement). Based on the Akka documentation (pre-1.0), it did not seem to be completely a "drop in replacement for scala actors" but I hope it's moving that way (and I'm very pleased that Scala is adopting Akka as the default implementation!).

Heh, yes, anecdotes are meant to be just that....

I also thought you were considering Akka as a language. The sentence where you mention "leaving 3 languages in the mix" gave me this impression.
Ah, I see. No, we have another language in the mix which is not relevant to this discussion. The "One True Language" comment was a bit tongue in cheek since I doubt we'd really end up with just a single language across all tiers. I had initially hoped Scala would become our primary backend language but it looks like that "honor" will go to Clojure as we're doing more and more work with that.
That document had display issues in chrome for me, and scribd wants to charge money to download the pdf. Here's a pdf link:

http://www.eecs.qmul.ac.uk/~mmh/APD/hacknot_book_a4.pdf

Thanks, your link is way better than mine.
>> I wonder how 15 hours in the post become a couple of days here on HN.

Average work day being ~8 hours, 15 hours == a couple of days :)

Awesome link that. Spent a few hours on it. Thanks :)