Tuesday, November 15, 2005

Sorority Initiation Movie

method for automatic updates, Rich Internet Applications with Ruby

recently intensively dealing with the creation of Rich Internet Applications. Most of these programs written in ActionScript 2.0. For the last week, however, dealing with writing small applications in RubyOnRails using libraries javascriptowych of asynchronous requests (ie AJAX).

main problem every programmer aplikacji WWW jest napisanie czegoś co nie będzie generować dużego ruchu w sieci. Pisząc RIA nie można się przed tym uchronić. Niestety model HTTP nie jest zbyt odpowiedni do tego typu aplikacji - o wszelkich zmianach w bazie danych klient dowiaduje się dopiero po wysłaniu żądania.



Przykładowo mamy prostą grę www, w której ruchy jednego gracza są obserwowane przez drugiego. Załóżmy, że gracz 1 co kilkanaście sekund dokonuje ruchu. Natomiast gracz 2 chciałby od razu widzieć co się wydarzyło. Teraz pojawia się problem - aby coś takiego uzyskać trzeba na przykład w odstępie 2 sekund wysyłać zapytania typu GET to the server to see if there was a movement in general. Assuming that the nearly empty GET request + response from the server consumes about 4kB (total return) so we 2kB / s for one player. If you have a link, say, 1 Mbit (~ 128kB), we are able to handle only 64 users at once (!). But keep in mind that we can have even two seconds slip with the present data.

lot about this problem and thought came to mind only solution for the creation of your persistent connections in both directions. However, today's firewalls or proxy servers will not let ... We must therefore stick to the HTTP protocol ...

But I came to solve the problem: D I do not know whether it is adequate and that certainly would work. However, I know that this is the best of my current practice ... : D

trick is to create nasłuchiwaczy. Nasłuchiwaczem is simply a client who wants to learn about changes to selected parts of the database. The client connects to the server while the server sends its response right away .... connection so the "hanging" until the one of the players will change some data in the database. When hanging thread receives this information - it generates a server response, then terminates the request. Nasłuchiwacz info gets so right away when the data has changed. When something like this nasłuchiwacz reconnects to the database because he wants to listen to again change.

solution is primarily an ideal, due to the fact that it works over HTTP. The only problem is timeouts. For example, proxy servers can wait a certain number of seconds to answer, then a disconnect. Then the customer has something to capture and connect again (of course, server-side hanging topic must also be removed.)

What do you think about this rowiązaniu? Is there any other contraindications to use such techniques?

0 comments:

Post a Comment