Disadvantages Of Adding Modules Without Using Genserver

OTP is a framework for building robust applications. It comes with a number of “components” to achieve this. Notably, supervisors and gen_* behaviours. These are just code that uses best practices that has been developed over the years. If you try to implement it yourself you’d implement the basics of an OTP behaviour anyway.

Many years ago, in the erlang world, OTP applications wasn’t a given and many projects are created without it. I attribute this to OTP not being pushed enough and under-documented. Note though it is not needed to build software but if you are going to do be running for a long time you win a lot by doing it.

A gen_server, or other behaviours are not fault tolerant per say but it is ready to be “plugged” into a supervision tree which gives you restarts, and hot code loading. The same goes with the other components.

Generally if you have something long-lived (and often for short lived things as well) you will reach for a gen_server because it gives you the ability to use in a bigger context.

There is value in spawning process without them being OTP behaviours and it is sometimes done when you want to complete a quick task but don’t want to run your current process. Normally you use at least spawn_link or at least spawn using monitors.

Some links (erlang links but you don’t have to look at the code if you don’t want to :D)

You might want to skim through http://learnyousomeerlang.com
it helps with understanding how the system developed and why OTP can help.

1 Like

What crashes is the process. When a process crashes it sends an signal to linked processes that then react.

If you spawn a process manually without linking then it just stops when it crashes. That is all.

If you link it to another process that traps the exit then this linked process can react by starting a new process. Or it reacts by stopping as well and sending a signal to the process that it is itself linked to.

Supervisors are basically process that trap exit signals of their workers and react. To start a process as a worker of a supervisor it must be an OTP process.

3 Likes

Now everything started be clear. Even i dont use genserver in my module, another processes use my modules. Using genserver in a module creates another processes tree right?

Yes, if your module is called from within a process in the supervision tree then it is run inside the existing tree (provided that the functions of your module do not spawn unlinked processes).

1 Like

I was thinking those extra applications use genserver and that is why we add them to extra aplications. I was calling that libraries OTP libraries because of i was thinking they use genserver. But when i search in httposion codes there is no genserver. Now i understand better thanks @all-forum

1 Like