EMQ Learning---Customer link resource consumption

Source: Internet
Author: User

Erlang process Consumption
EMQ a policy that separates client links using the link process (emqtt_client) and session process (emqtt_session). When an MQTT client connects to a EMQ server, a process (emqtt_client) is first established that manages the connection, and when the client is validated, another process (emqtt_session) is established, which is responsible for the client's session.

In Emq, each clientid can only be logged in once, so the client who logs on will kick the client first.

Primary memory consumption (a connection of approximately 10K RAM)
Data Sheet
When a client successfully completes the validation, EMQ adds a table item to the Mqtt_session and adds the table item to both the ETS tables in Mqtt_local_session and mqtt_client.

Process context
The link process (emqtt_client) is responsible for receiving data from the client and accepting data from the server to be sent to the client, and using codecs for codec, so the context consumption of the linked process depends primarily on the packet size received and the size and number of packets to be sent.

The session process (Emqtt_session) maintains a inflight queue, which is used to reply to a message with a QoS greater than 0, and the default is to save 32 messages waiting to be answered, which will be placed in the waiting queue if the magnitude is exceeded. Therefore, the main memory consumption of the session process (emqtt_session) depends on how many messages are waiting to be answered, and the size of the packets that need to answer the message.

Main CPU consumption
Timer
The link process (emqtt_client), which starts a heartbeat timer by default, periodically checks to see if the link is alive. The session process (Emqtt_session) also opens a resend timer to check the infligt response of messages with a QoS greater than 0, and when the client publishes a 2 QoS message, another timer is opened to detect the response of the REPL information. Of course, the session process (emqtt_session) is likely to remain offline for a period of time, so during this time a timed out timer is established. So the session process (Emqtt_session) has three timers at a time.

Monitoring
The session process (emqtt_session) establishes a monitoring for the link process in order to discover the link process's exit. After the successful completion of the client on-line, when adding items to Mqtt_local_session and Mqtt_client, the two ETS tables are set up with two monitors to monitor the session process (emqtt_session) and the link process (emqtt_ Client) exits.

Process messages
Because EMQ uses a separate policy for the link process (emqtt_client) and session process (emqtt_session), it is unavoidable to generate process message delivery. Because the session process (Emqtt_session) is responsible for receiving the message sent to the client by the server and processing it, and then paying the link in (emqtt_client) to send it.

When using the persistence session, a large number of process messages are generated when the session process (Emqtt_session) is found and restored.

Summarize
As you can see from the above introduction, before deploying a EMQ server, you need to consider the magnitude of a client's average message, the ratio of the QoS to the packet, and the size of the packets, depending on how many clients are choosing the CPU frequency and number (refer to the scheduling section in the Actor model).

When operating a EMQ server, if the volume of messages and the number of clients without significant changes in the case of a sudden spike in the CPU, it is necessary to consider whether the client frequently up and down the line situation. Of course, this is just a simple example, there are a lot of things not listed here

EMQ Learning---Customer link resource consumption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.