Rough, but worth it.

The last month has been rough.  Scala drives me to either completely love it, or it makes me want to bathe in the blood of its creator’s children.  This month has been full off bloodlust.  I love to bitch about Scala, Typesafe, and the poor decisions that have been made regarding the language and its popular libraries; however, once things are working, they work well, and they work fast as hell.

If you’re working with people that try to make Scala look like Haskell, it’s a nightmare.  That is a lot of the problem.  It isn’t haskell.  I don’t want to grow a neckbeard and try to understand punctuation as code.  If you write code like that, and I have to work on it, I will want to pour hot coffee on your babies.  I’ll be thinking it every time that I talk to you.  Readability trumps writability EVERY SINGLE TIME. I’m not the only one who feels this way. If you work with people that care more about readability than writability, and you don’t mind reading about what the underlying JVM is doing with your code, Scala is a delightful language to work in. Someone needs to write a Scala (the good parts) book though; and someone also needs to write a guide that works like the Elixir guide. Show people how to build a server with akka and Scalatra instead of showing way-too-clever ways to calculate/memoize Fabonicci and we’d be on to something.

I spent the last month battling issues that I assumed were caused by the PlayWS standalone http client library using a single thread per connection. Then I read some whitepapers on how Java nio works (it’s really badass), realized that WS uses Java nio and that the library couldn’t be the cause of my problems, fired up a yourkit profiler demo, and discovered that my problem was actually that I was using Scalatra routing in such a way as to block an entire thread waiting for the Future returned by WS to complete. No, I didn’t call Await.* or anything on it. I just returned the future to the route. Scalatra doesn’t like that though, as then the call to your route doesn’t free up the thread until the Future completes. All you have to do to prevent the issue that I encountered, and make your calls actually asynchronous, is to have your external call return a promise or use the AsyncResult object correctly. Basically, just follow the instructions for Scalatra. Scalatra is awesome. I wish every library in Scala was so straightforward. Those guys totally get it. I can’t say enough good things about them.

Anyway, I went from struggling to handle 2000 simultaneous external calls and crashing due to memory exhaustion to easily handling 300000 simultaneous external calls on less than 1GB of memory (I did have to increase my ulimit file count on the OS to keep from running out of files). I will likely be able to tune that up even more. I wouldn’t have guessed where the problems were without the profiler. The yourkit profiler is worth every penny that they charge for it. I bought it the second I fixed my problem. I think everyone should support them as well. They’re doing great work.

Anyway, I guess the gist of this is that Scala is an amazing language when you use it on the regular; but, someone not associated with Typesafe needs to write a “good parts” book and associated style guide. It really could be a very popular language if someone would wrestle it away from the academics and neck-beards. Maybe I’ll do it some day when I have a little more time.

Published by


Geeky musician born and raised in Wyoming and currently living in Denver CO.

Leave a Reply

Your email address will not be published. Required fields are marked *