In the phoenix framework controllers with their action functions handle http requests and channels handle two way communication.
I would like to know if Controllers and Channels are actual OTP genserver, if so I would like to have some details on how are these created, supervised and pooled in the Phoenix framework.
I am concerned about the fact that Controllers and channels may become contention points in my application and I did not find any resources discussing the aforementioned concern.
This is a great question. The architecture for channels vs HTTP requests is pretty different, so let’s handle them separately.
HTTP: Ultimately Phoenix doesn’t really do anything process architecture wise, instead it’s up to whatever actual web server the Phoenix framework is sitting on. By default that’s gonna be cowboy. You can read more about cowboy’s process architecture here: https://medium.com/@kansi/erlang-otp-architectures-cowboy-7e5e011a7c4f. These processes are not genservers, they are created to handle a particular request, and generally die at the end of that request.
Channels: Much like webservers, each individual connection is going to get their own process. Unlike webservers however, these processes are indeed genservers. Don’t think of it like a pool of genservers waiting around for users though. A new genserver is spawned for every web socket connection to a user, as well as for each channel the user joins. You don’t really need to worry about bottlenecks here either, consider: http://www.phoenixframework.org/blog/the-road-to-2-million-websocket-connections
Actually no, but thank you for the info. I didn’t know there where a pre-configured limit for the maximum number of connections. This might be useful for me someday.