Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> in other languages you can have issues where a rogue regex or bug or whatever can cause runaway CPU consumption and either crash the node, or starve resources from other processes; well, this isn't as big of a deal on Elixir because the BEAM uses pre-emptive scheduling to prevent individual processes from causing big issues.

Right, so where other languages would rely on external cloud infra to kill nodes that are seizing, BEAM does it out of the box. That's cool. Though I do think eg Kotlin coroutines are probably capable of similar things. (but they are only recently coming out, vs BEAM which has had this out of the box by default for ages)



> Though I do think eg Kotlin coroutines are probably capable of similar things. (but they are only recently coming out, vs BEAM which has had this out of the box by default for ages)

Most other green-threads end up only yielding on I/O; at least I've not seen any other system where instructions between yield points is bounded[1]. In that case, if you have enough green-threads things that want to run a CPU loop, you can lock up all the OS threads that run green-threads. If you have just one in a CPU loop and you ever need to do anything across all the OS threads, that could get you stuck, too.

[1] Erlang doesn't have a specific bound; you could make a really long function, but without a loop construct, you'll be forced to call a function eventually, and function calls are yield points.


I’m not sure most other languages such as Kotlin implementing coroutines/green threads would be able to support it in the same robust way though. Pre-emptive scheduling means that the runtime will actively stop a resource hungry routine, so that other routines can have a turn. If a goroutine or Kotlin coroutine is spinning in a tight loop, it may just spin forever if it doesn’t do a syscall or whatever the runtime uses to check in and say, hey, do any other processes need time?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: