How did WhatsApp achieve 2 million connections per server?

If you have enough RAM it’s not too hard to handle 1M or more connections on linux. These guys handled 10 million connections with a java application on a single box using regular CentOS kernel with a few sysctl tweaks: sysctl -w fs.file-max=12000500 sysctl -w fs.nr_open=20000500 ulimit -n 20000000 sysctl -w net.ipv4.tcp_mem=’10000000 10000000 10000000′ sysctl …

Read more

How do you write a fun that’s recursive in Erlang?

Since OTP 17.0 there are named funs: 1> Perms = fun F([]) -> [[]]; F(L) -> [[H|T] || H <- L, T <- F(L–[H])] end. #Fun<erl_eval.30.54118792> 2> Perms([a,b,c]). [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]] Before that you could do this with a little argument trick: 1> Foo = fun(F, X) -> F(F, X) end. #Fun<erl_eval.12.113037538> 2> Foo(Foo, a). <…infinite loop!> …

Read more

How do you create and load modules dynamically at runtime in Elixir, or Erlang?

As you described, there are many different approaches you could take by ultimately they boil down to two different categories: 1) code compilation and 2) code evaluation. The example you described above requires compilation, which will define a module and then you would have to invoke it. However, as you found out, it requires defining …

Read more

Erlang: what is the difference between “include_lib” and “include”?

The way the documentation describes the difference between include and include_lib is: include_lib is similar to include, but should not point out an absolute file. Instead, the first path component (possibly after variable substitution) is assumed to be the name of an application. Example: -include_lib(“kernel/include/file.hrl”). The code server uses code:lib_dir(kernel) to find the directory of …

Read more

How do you design the architecture of an Erlang/OTP-based distributed fault-tolerant multicore system?

Should I just start with a few gen_servers with a supervisor and incrementally build on that? You’re missing one key component in Erlang architectures here: applications! (That is, the concept of OTP applications, not software applications). Think of applications as components. A component in your system solves a particular problem, is responsible for a coherent …

Read more

Good resources on using functional programming in game development? [closed]

Well, you could do worse than studying the code of some of these haskell games. Some of these use FRP (functional reactive programming), which some people are working on as a pure, high-level technique for games and other things. But most are a typical haskellish mixture of effectful and pure functional code. Bloggers with relevant …

Read more