RABBITMQ, whose networking part is often analyzed by many Erlang programmers and enthusiasts. When I was young, I saw a lot of people write about this blog, such as:
1, http://www.blogjava.net/killme2008/archive/2009/11/29/304079.html
2, http://jzhihui.iteye.com/blog/1544779
Basically, it's a very simple and straightforward structure.
RabbitMQ Networking Monitoring tree structure
Use observer to view the RABBITMQ networking's monitoring tree structure, which is roughly the case:
which
1, Rabbit_net_sup is the main supervisor process of the whole RABBITMQ
2, Process <0.47.0> is an instance of Tcp_listener_sup, because RABBITMQ's networking allows multiple ports to be listen at the same time, so tcp_listener_sup here is an anonymous process
3, Process <0.49.0> is an instance of the listen process that is responsible for listening to the port and Start_child performing a number of acceptor processes under the TCP_ACCEPTOR_SUP monitoring process
4, tcp_acceptor_sup_:::19000 is the monitoring process for all acceptor processes
5, Process <0.50.0> is the acceptor process of the instance, responsible for asynchronously receiving the newly established socket and executing the OnConnect function, creating the client process under the RABBIT_TCP_CLIENT_SUP monitoring process
6, <0.267.0>, <0.268.0>, <0.270.0> is the client process, and each client process corresponds to a socket
In the actual RABBITMQ, the client process is a supervisor process in which the package includes a rabbit_reader process and a helper process
RabbitMQ Networking Code Structure
For a clearer study of this part of the code posture, I made a simple code extraction, RABBITMQ the networking code alone out of a application. The code module is roughly like this:
(Haha, sublime is a little lighter than Emacs, after I don't have Emacs, my computer is a lot lighter)
This includes:
1, File_handle_cache, Gen_server2 is an auxiliary module
2, Rabbit_net_app is the start of application and the boot net
The process of boot net is divided into three main parts:
2.1 Assign EPMD to the port of this node and write to Mnesia
2.2 Start Rabbit_tcp_client_sup and declare its working sub-process
2.3 Start Tcp_listener_sup, Tcp_listener_sup will start tcp_acceptor_sup_:::19000 process and listen process successively, tcp_acceptor_sup_:::19000 The process declares its own child worker process (that is, the acceptor process), the listen process listens on the port and start_child the specified number of acceptor processes under the tcp_acceptor_sup_:::19000 process
Community-related
In the community, there are a lot of people with RABBITMQ networking do some things, such as recently and small partners to discuss more ESOCKD, in general, the author is based on RABBITMQ networking as a blueprint, on the basis of some code structure adjustment.
Summarize
EPMD Extensibility Read: http://blog.yufeng.info/archives/539
RABBITMQ--Networking