Openfire server presence (online status) Message Processing Process

Source: Internet
Author: User
Presence processing is the core of IM server and the most complex part of IM server. A user's status changes and needs to be automatically delivered to all his online friends through the server. Therefore, the presence module actually waits for the same message processing server. For more information, see Article Activemq Performance Research and comparison with memcacheq.

The complexity of presence is reflected in:

1. Since each user has one or more friends, the server's processing capacity is magnified.
2. Due to the complexity of distributed processing, your friends may be distributed on N servers at the same time, and the friends that are online at the same time are irregular.
3. The request volume is unbalanced and may be instantaneous. For example, when your server is restarted, all customers will automatically reconnect at the same time. For example, when Twitter goes down in some hot events, everyone's activity suddenly increases. Therefore, the system must be designed based on the Peak throughput.
4. Difficult cache design. Each user's online friends are different and changing at any time.
5. the business logic of stealth and blacklist is difficult to efficiently process.

The process for openfire server to process presence is as follows, which is subject to 3.6.0.

1. connectionhandler. messagereceived ();
Mina-level processing.

2. stanzahander. Process () => processpresence
XMPP layer. To process all XMPP packages, only the login-related packages are processed here. Other types of packages are processed by related logic classes. Because it is a presence package, it is submitted to the following presence logic processing module. (Also add from to packet)

3. packetrouteimpl. Route () // route presence
4. presenceroute. Route () => handle () // route presence
Because presence is a packet to be routed, the routing mainly distinguishes whether the target is local or remote, whether it is component/server or a common user.

5. presenceupdatehandler. Process () => broadcastupdate
// Process () Update dB and update cache,
CILS presencemanager. useravaliable (); Session. setpresence ()...

6. Roster. boradcastpresence ();
Check the privacy list (invisible and blacklist users) and route it to all online friends.

7. routingtable. routepacket, routetable. getroutes ()
The real work here is slow.

8. session. Process (), session. Deliver
The user has been distributed to the relevant user, and the session of the user is called and delivered to the user.

9. nioconnection (). Deliver, deliver to the end users
Back to Mina

Therefore, the core of presence's delivery work is 6 ~ 7. However, there are many details about other steps. 6 ~ in openfire ~ 7 is simple and elegant, but there is still room for improvement as a large and efficient message delivery system.

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.