Tell HN: I'm writing an Erlang recipes book, are you interested?
leanpub.com
leanpub.com
Or to say it slightly differently : I'm not that much interested in recipes about the Erlang language itself, but I'm very very interested in recipes/examples of architectures of actual Erlang/OTP softwares.
I'm doing mostly Python these days, but I worked on a couple of side projects in Erlang in the past (a large one ~3 years ago, and a small one ~6 months ago). And for me the hardest was (and still is) to figure out how to use the OTP behaviors in an optimal way. How to make a nice, working supervision tree.
I managed to pull working stuff out of the ground, but somehow it never fell OTPish. I couldn't tell if I did it right or wrong.
It has examples on how to build network servers (TCP RPC server, HTTP server, a caching service, setting up a distributed system with multiple nodes, resource discovery, logging, release managing, interfacing with C code and many other useful things).
Our site lets authors raise funds for promising book projects. Like Kickstarter it's all-or-nothing where contributors only pay once the goal is met. If the goal is met authors receive the raised funds, minus 5% and processing fees. We've just went live, and our biggest challenge now is finding book projects people would be interested in funding. This may be such a project :)
</plug> (sorry! :) )
However, some aspects of the recipe book should be task oriented:
- Web server hosting static files using the standard inets server, and 3rd party libraries like webmachine, nitrogen, and yaws. - How to log - How to enable tracing
etc.
"Erlang in the Real World"
From the top of my head:
- portraits of companies and products who are using erlang
- what does erlang do for them, that is not available in mainstream stacks
- discussing their infrastructure and design desiscions as detailed as possible
- what did they learn
- how are they involved in opensource projects
- numbers and figures of their running systems
This could be a win-win situation. Companies can show their cool stuff. We can learn in what cases Erlang is a good solution.
Anyway - Good luck with your book.
I know for a fact there were some really good talks on development & deployment experiences.
Hope this helps.
Who restarts who? That's a bit tougher to do when everything becomes cyclic.
Links are bidirectional though, so when one of the workers die, the other can know about it, die, propagate the error or react to it. Monitors are unidirectional and won't propagate the errors, but only report it. I guess you could write your own mutual supervision that way, but it would be a bit weird, still.
The first one is distributed Applications. This is part of the standard OTP stuff. What this does is declare a node as a master, and then failover nodes for your OTP application. When your master goes down, the other nodes take over it. Whenever the master is back, the failover nodes drop their applications and restarts it on the master. This loses all of the state if it hasn't been kept in a safe place.
Another one is to look at gen_leader. gen_leader is not part of OTP, but has been written by Ulf Wiger and is available on github or through agner. A quick description of it would simply be to say that it's a boosted gen_server that will find a master of itself somewhere and automatically replicate its data everywhere else. If the master dies, a leader election occurs and a new one takes over.
A third option is to have a masterless concept. This is what happens in Riak. Data has to be shared in clever ways and code organized to support such a design. Nobody's a master, everyone's a follower. You add redundancy here and there, push important state to a safe spot, etc. In the standard library, modules such as 'global' handles this kind of thing.
Supervisors are not exactly made to cross node boundaries. They protect your local processes. If you need something more complex to keep your state alive, this usually happens at a higher level for OTP.
That being said, riak_core has been on my List Of Things To Have A Really Good Look At for a while now...
By doing this you are not limiting the queue to the size of 1. If you have N producers, you can have more than N elements in the queue, but the idea is that each producer can only enter them one by one, with the agreement of the consumer. Nothing would stop the consumer from accepting a thousand of them before waiting before replying, therefore slowing down the producer. The idea is just to limit the rate at which you accept queries by tying it to the speed of the consumer.
If this is not enough, you can look at things like the jobs tool (https://github.com/esl/jobs) to work with scheduling.
By the way, you're mistaken on the idea of message sending always succeeding. The idea is that you will never error out because of trying to send a message (send and pray), not that the message will make it to destination. If you want any guarantee that the message made it, then you need that acknowledgement async message being sent back to you.
(you can make a data structure which makes memory explode, for instance lists:seq(1, 123456789123456), you can make a program which makes memory explode, for instance by growing the stack enough. Why is a message queue special?)
What happens if the message you can't add is a specific system message that allows the suspension of OTP processes for a code upgrade? Do you end up livelocked? How do you propagate back that you couldn't insert your element in the queue? Do you make message passing an operation that can fail? How would that work over the network when the message telling you something failed is lost over a netsplit? Is it a different kind of failure?
This has very deep design repercussions on the language. It's not impossible, but it wouldn't let Erlang be the same.
Thanks!
You might throw some client-side validation on those fields to help rebels like me who can't follow simple directions. =)
Thanks for letting us know!