Wise Chat Pro is a very popular chat plugin for WordPress and BuddyPress. We have received many positive reviews from our satisfied clients. We constantly work on improving both features set, the appearance and the performance of the plugin. A purpose of this article is to describe why our plugin sometimes might encounter performance difficulties.
A bit of theory
It is not a complex technological knowledge, but understanding the following piece of information is required to fully understand how chat plugins for WWW are built and what issues might they encounter.
There are two ways to build a chat plugin for a web site. Each of these two approaches relies on a different server communication method:
- AJAX powered communication
- WebSockets powered communication
AJAX powered communication
This is the most common way of communication applied in chat plugins. It is also relatively easy to implement, install and also easy to maintain on the server as it requires almost no attention. Basically, the chat periodically checks for new messages and displays them if there are any.
To be precise, every 1-20 seconds the plugin initializes a request to the web server (called AJAX request) which purpose is to check if there are new messages posted by other users. Because users may post messages very quickly the chat has to check for new messages quickly too. It is usually from 1 to 20 seconds period and it can be configured in Wise Chat Pro. The greater delay the worse chatting experience because users must wait longer for replies of other users. The lower delay the more requests are made and more requests mean greater server load.
Assuming that there are 10 users in your chat channel at the moment and the delay is set to 5 seconds then this contributes to 120 requests per minute. If you lower the delay to 1 second it will generate 600 requests per minute! As you can see this simple change can highly increase the load of your server. When your server has an older CPU or has not enough of RAM memory or simply there are a lot of chat visitors at the moment then this may be causing one (or more) of the following issues:
- chat messages are sent slower
- chat messages are received slower
- other pages on your WordPress instance are loaded slower
- other websites on the same web server are loaded slower
- CPU of the server has a high load
- there are a lot of database connections initialized in the same time
Despite these downsides AJAX powered communication has a lot of advantages:
- it is quite easy to implement by plugin’s authors
- it is very easy to install because a regular plugin installation is sufficient to get it working
- there is no need to use additional third-party (usually: paid) servers
- it is not needed to do a regular maintenance work on the server
- it works on every modern web browser both desktop and mobile
To sum up:
- medium / low
WebSockets powered communication
This is less used method of communication, however, it delivers much higher performance. Instead of making frequent checks for new messages the chat plugin establishes a constant connection with the server. When a new message is posted the server sends it directly to the chat and then it is displayed for user. The connection cost is very cheap and it does not occupy so much server’s capacity. Although there is a limit of connections, but it is a quite big number.
WebSockets communication is highly efficient, however, it has a lot of disadvantages:
- it is not easy to implement software based on WebSockets
- it is not easy to install a plugin supporting WebSockets because it is additionally required to run a separate chat server despite the fact WordPress is already installed on PHP server
- there is often a requirement to use server based on Java, it is more efficient than PHP-backed server
- it is also required to do regular maintenance tasks on the server and this cannot be done without special knowledge
- all this may be difficult for novice users
To sum up:
- average difficulty
- average difficulty / hard
- average difficulty / hard
Wise Chat Pro relies on AJAX
We have chosen AJAX communication method for our plugin. We have always wanted to make the plugin easy to install, use and maintain. A separate server, that is required for WebSockets option, is beyond the scope of most of potential users. Below is how we improved AJAX communication. Our solution is sufficient for most of our clients.
Here are some ideas that might help to improve the overall performance of Wise Chat Pro:
- Lightweight AJAX engine: We created our own AJAX engine dedicated for Wise Chat Pro. It has much better performance than the default WordPress AJAX engine. Make sure you use this engine. It can be found in Advanced tab on Wise Chat Pro Settings page.
- Refresh Time: As we described above the higher refresh time (delay time) the lesser server load. You can try to increase refresh time. It can be found in Advanced tab on Wise Chat Pro Settings page.
- Users limit: You can limit the number of users that are allowed to chat in one channel at the same time. Less users means lesser server load. You can set the limit in Channels tab on Wise Chat Pro Settings page.
- Pages limit: Put Wise Chat Pro only on dedicated pages. Some clients install the chat on every WordPress page they create, but this can make a great load to the server. Maybe the chat is needed only on a special page called “Chat” or on home page.
- Server capacity: Ask your server administrator if there is something that can be done in terms of higher capacity.