5 ms·
> 1) A lot of this sounds like OS style scheduling. This is probably a mixed bag. On a machine that's devoted to software in Erlang, you will ideally run one s
by toast0 11y ago
> 1) A lot of this sounds like OS style scheduling.
This is probably a mixed bag. On a machine that's devoted to software in Erlang, you will ideally run one scheduler (OS thread) per core pinned to a core, plus however many dirty/async/io schedulers needed/configured. You'll also have a couple other OS processes running (ntpd, sshd, crond, etc). So the OS will have an easy time with scheduling processes, the majority of the time you'll have one thread to run on the core, or one thread on the core waiting for io / other signals. On the other hand, you do have Erlang doing work that the OS could conceivably do; but I wouldn't really want to put one million threads into an OS scheduler (maybe it works, but I don't know).
> 2) sending to a larger mailbox takes more resources
As felix said, it costs more reductions, but there might be a real cost too; a larger mailbox probably means more senders sending (although it can also just mean slow processing), and if there are more senders sending to the process, there is more contention on the message queue lock, more info on how messages are added to a mailbox here[1]. There's not a concept of mailbox capacity, the queue is a linked list; any mailbox can expand until you run out of swap, or hit the configured memory limit, either way the whole OS process dies[2]. I'd guess the reduction cost for sending a message is a function of the number of messages in the queue, it's possible it's a function of the total size of all the messages, but I don't know if that's tracked.
Edit: i meant to address > 3) Are there foreign function interfaces that could allow you to get Erlang style concurrency with other languages
Not that I've seen. You can do NIFs, ports, or port drivers, but that doesn't really get what you're asking for. There are some other languages that run on the BEAM VM, maybe one of the Lisps you could take existing Lisp code and run it, but generally the BEAM languages are not available outside the BEAM. If you wanted to run an existing language within BEAM, that language would need to have hooks to embed in another program, and the hooks would need to let you do a small amount of work at a time; or you'd have to re-implement the language in a BEAM friendly manner.
[1] http://erlang.org/pipermail/erlang-questions/2011-September/061050.html http://erlang.org/pipermail/erlang-questions/2011-September/...
[2] This isn't very great, and one of the areas where Erlang's isolation is weak -- one Erlang process can eat all of limited global resources, for example ram, ports, ets tables, atoms and the result is often the whole VM stops, either it directly exits, or core applications will shutdown when they hit a failure they can't handle (for example mnesia really needs to be able to have the ets tables and file ports it needs, and will shutdown when it can't get them, often this will result in your application crashing enough to get shutdown)
- andy_ppp 11y agoReally surprised at [2] given how robust BEAM is elsewhere. Seems it would be simple for a supervisor to be able to check sizes and kill processes over a certain size. However, actually thinking about it the hot swapping of code and supervision probably works because all the messages/ports/ets/atoms/results can sit there separately while the process can be replaced. Thanks for the info!
- ramchip 11y agoInterestingly, there's discussion going on right now about adding a similar feature: http://erlang.org/pipermail/erlang-questions/2016-April/088960.html http://erlang.org/pipermail/erlang-questions/2016-April/0889...
- toast0 11y agoGenerally, an erlang supervisor is just waiting for processes to die and react to it; I'm not sure it makes sense to also have it taking an active interest in processes, but you could quickly build something that periodically calls erlang:process_info/2 on all processes, and kills them if they're too big (for whatever value of too big). That would get you protection from one process consuming too much ram, and maybe ports (assuming a process is going to link to its ports, you can examine the links), you could also scan ownership of ets tables. You can't really track which process is using up all the atoms though.