Skip to content

Comment on Ask HN: What equivalents of Erlang/OTP exist for other languages?parent

Comments

There is no simple way in Java, for example, to continue processing requests in the application while you shutdown and restart with a new version

It's not trivial, but Java certainly supports hot code swapping. How hard it is to use it depends on how much you want it to do, like preserve state etc. For stateless services its not hard to load the new version using a new class loader to live side-by-side with the old one, and then kill the old one (automatically) once all its requests have completed, and let the old code be collected by the GC.

It's something you could arrange if you wanted to, but it could be pretty complicated! Swapping individual classes within a VM and having multiple classloaders could be very nuanced to debug. I suspect it would also complicate usage of concurrency and primitives -- for example, there will be a separate EventBus for each classloader, rather than one for the application. The app will need to embrace subtlety like that to be correct. I'd almost be tempted to consider the two classloader roots to be two separate apps in the same process, but they'd need to share the same file descriptors for network communication and logging. Urk.

It's a neat idea though. Do you know of any frameworks that would make the idea easier to implement? It sounds loosely similar to the Unix availability concept of passing off the listening socket to a new instance of the process, while allowing the old processes to linger until they finish serving their requests.

All other things equal, I favor architectural approaches where I can take any machine offline safely and effortlessly since I tend to need to handle that case anyway for availability reasons.

for example, there will be a separate EventBus for each classloader

Not if you leave the message classes alone.

Do you know of any frameworks that would make the idea easier to implement?

No, just careful design (JRebel is for development rather than production, as I understand, but I could be wrong) Tooting my own horn (again) but Quasar does hot code swapping for actors (including state preservation)[1]. This is possible (as it is in Erlang) because actors encapsulate their own state.

[1]: http://docs.paralleluniverse.co/quasar/#hot-code-swapping

I think the most commonly used framework is JRebel: http://zeroturnaround.com/software/jrebel/

According to the FAQ, it doesn't create multiple class loaders, it just extends the exiting ones.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.