If I would like to create an AJAX chat, what communication technology should I use to maintain scalability?

I put together AJAX chat some time ago ASP.NET MVC and jQuery. Javascript hit the server every 7 seconds to check for new messages. Obviously, this was terrible in performance as the chat grew and included more and more users. Website traffic grew exponentially with a large number of requests. The user could leave the computer all day and not even be there, and they would still make hits every 7 seconds.

Is there a better way to do this? I heard of something called a “push,” but I was not able to circle my head around it. I think I just need to point in the right direction.

1.) What is the best way to develop AJAX chat and its scalability?

2.) What is push and how can I do this using jQuery?

+4
source share
4 answers

1.) What is the best way to develop AJAX chat and its scalability?

I agree with @freakish about the complexity and potential lack of IIS scaling.

However, in works called SignalR , which could become a major part of ASP.NET, there is a relatively new Microsoft option. More in this related SO Question:

2.) What is push and how can I do this using jQuery?

Partially answered elsewhere, but this is a long-term permanent connection between the server and the client, which means that the server can instantly "click" the data to the client when it has new data available.

jQuery supports the creation of AJAX requests, but the main library does not support ways to publish HTTP requests or HTTP streams. More information in this SO answer to "Long polls / HTTP streams General questions . "

+1
source

Server push is a technology that allows the server to send data back to the client without forcing the client to make many requests (for example, every 7 seconds). This is actually not a javascript issue, but a good server-side scripting. The upcoming HTML5 will simplify the use of events sent by the server and / or WebSockets . This will be a true TCP connection between different machines.

But if you intend to make the web page compatible with older browsers, then the most common method is a lengthy survey. The client sends a request to the server, and the server does not respond to it until it receives new data. If so, then the answer is made, and the client immediately after receiving the data calls the server with a new request. In practice, however, this requires the server to be well-written (for example, it must support thousands of downtime at the same time) and can be quite a challenge for developers.

Hope this helps. :) Good luck!

+1
source

The technique you should use is constant, real-time, long-term connections through a web page using WebSockets. You can use this library .

+1
source

Node.js is becoming quite popular for creating something similar and supports socket connections, so you can only push data when a new message appears. But it will learn something completely new.

Another nice potential would be to use MVC OutputCacheAttribute and use the SQL dependency parameter so that your AJAX page can be cached and will only be a new request when a new chat message appears. Also, you would like your controller to be an asynchronous controller to reduce the load on IIS.

Enjoy, optimization is always fun and very time consuming!

0
source

All Articles