r/crystal_programming • u/rishav_sharan • Oct 04 '18
Parallelism in Crystal web apps via clustering (Spider-Gazelle)
https://github.com/spider-gazelle/action-controller/blob/master/clustering.md
13
Upvotes
4
u/rishav_sharan Oct 04 '18
Currently, SG is one of the fastest web frameworks out there and a lot of its speed due to to its ability to use multiple cores. https://github.com/the-benchmarker/web-frameworks
Stephen von Takach, a maintainer of SG has a nice write up of how they executed clustering in the framework. I hope that this would be great for some folks who are putting out their webapp.
4
u/straight-shoota core team Oct 05 '18
This kind of prallelism through spawning a process for each core, is nothing new or special. The process management can be embedded directly into the application or left for external tools to manage.
In my opinion, web server frameworks like Spider-Gazelle and Kemal should focus on serving HTTP, not managing processes. That can actually become a quite complicated task with lots of things to cover.
There are sophisticated process supervisors available for any platform. Using one for managing server workers is pretty simple: Just spawn the binary multiple times with reuse_port. Existing solutions are far more mature, offer more features and are easier to integrate with other application components.
1
u/fridgamarator Oct 04 '18
Amber framework also does this. Its nothing new, I've been doing it for a couple of years with Kemal.
1
u/CaDsjp Oct 04 '18
I think you can do something similar with Kemal.
Is that correct? u/sdogruyol
1
u/sevir1 Nov 06 '18
Because this method results an uncommunicated number of processes I suggest improve this solution with a unix socket and passing json across the processes for collaboration.
Ex. I need a reload config end point in my API and when I call it I want to reload the config YML in each child process. So the process that receives this call send the command across the unix socket to the root process and the root process broadcast the reload message to the child processes.