I’ve been trying to learn and study how OTP/Genserver/Flow works within the context of a web application and am at the point where I grasp the concepts but think it would really solidify the lessons if I “look under the hood” in a real web app project.
Does anybody know of any projects?
I was going to post this in the projects section but couldn’t find anything there.
Here is my authentication library. It may help to look at it because its quite small for the most part. Uses genserver and sub supervisor to manage tokens(the actual logic probably needs cleaned up though).
it may be the case because of it being serial but it would have to be A LOT of reads because it just does key lookup on a map. But yes that’s definitely something I am thinking about for the next version. That or a dynamicSupervisor that creates a genserver process for each “session”
It just said “service” in its description, so I assumed it gets a lot of reads … There is a library, goth which keeps it’s config in a genserver, and it was a bottleneck for me. And I didn’t have A LOT of reads. I used it to generate signed urls for google storage and on each request there were two calls to a single genserver (Goth.Config)… I first moved it to ets, and then to compiled modules, since the config rarely changes. The performance gain was quite significant. And it also seemed cleaner, but that’s subjective.
That or a dynamicSupervisor that creates a genserver process for each “session”
ets approach would be simpler to implement and probably more efficient.
I learned elixir in a similar way by grinding away and trying things on genserver so I may have a couple useful examples. For a bigger app, here is a section of code in my data project that has several supervisors and genservers for solving a simple need of having a cache with very specific expirey logic (activity counts in a rolling time window):
You can find the the full web project and such easily from there, it has a lot of code ranging from high comfort level down to first learning or powering through objectives to get somewhere.
And here is a simpler and very small library that just handles keeping simple site statistics, that happens to have a genserver implementation in case of wanting to hold stats in memory instead of a database.
Hope they help. I can post code snippets of Flow usages that I used at work recently as well if your interested. I’ll do my best to answer any questions if you do take a look.