Say you have a web page that is supposed to continuously update the positions of ships in the ocean or something similar. I am wondering what is a good approach for this ? The page updates automatically without the user hitting any buttons or clicking on anything. What occurs to me is a timer that goes off in JavaScript every couple of seconds and sends a request to the Rails server. The Rails server may send back a Javascript call or a series of calls with some data in order to update the position of the ships. Basically the ships positions are maintained on the server which gets live feeds of where the ships are. I have done similar types of things such as periodically_update() in rails. Sometimes these polling type things get carried away and tons of them get sent to the server. It could be that say there are 10 clients and each of them sends a request every couple of seconds so now you have basically that many more requests and so on. Also if the server gets behind on requests, the client keeps on sending them. For whatever reason, it seems like a pain in the neck these types of polling actions. They seem to clutter up the log file really bad and possibly slow everything down in some situations. but I am not sure if there is any other way to do this ? If not is there a more optimal way to approach the polling I wonder ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 Feb 2012, at 06:29, Jedrin wrote:> Say you have a web page that is supposed to continuously update the > positions of ships in the ocean or something similar. I am wondering > what is a good approach for this ? The page updates automatically > without the user hitting any buttons or clicking on anything. > > What occurs to me is a timer that goes off in JavaScript every couple > of seconds and sends a request to the Rails server. The Rails server > may send back a Javascript call or a series of calls with some data in > order to update the position of the ships. Basically the ships > positions are maintained on the server which gets live feeds of where > the ships are. > > I have done similar types of things such as periodically_update() in > rails. Sometimes these polling type things get carried away and tons > of them get sent to the server. It could be that say there are 10 > clients and each of them sends a request every couple of seconds so > now you have basically that many more requests and so on. Also if the > server gets behind on requests, the client keeps on sending them. For > whatever reason, it seems like a pain in the neck these types of > polling actions. They seem to clutter up the log file really bad and > possibly slow everything down in some situations. but I am not sure if > there is any other way to do this ? > > If not is there a more optimal way to approach the polling I wonder ?You could use pushing from the server instead of polling. http://railscasts.com/episodes/260-messaging-with-faye Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 Feb 2012, at 09:24, Peter De Berdt wrote:>> Say you have a web page that is supposed to continuously update the >> positions of ships in the ocean or something similar. I am wondering >> what is a good approach for this ? The page updates automatically >> without the user hitting any buttons or clicking on anything. >> >> What occurs to me is a timer that goes off in JavaScript every couple >> of seconds and sends a request to the Rails server. The Rails server >> may send back a Javascript call or a series of calls with some data >> in >> order to update the position of the ships. Basically the ships >> positions are maintained on the server which gets live feeds of where >> the ships are. >> >> I have done similar types of things such as periodically_update() in >> rails. Sometimes these polling type things get carried away and tons >> of them get sent to the server. It could be that say there are 10 >> clients and each of them sends a request every couple of seconds so >> now you have basically that many more requests and so on. Also if the >> server gets behind on requests, the client keeps on sending them. For >> whatever reason, it seems like a pain in the neck these types of >> polling actions. They seem to clutter up the log file really bad and >> possibly slow everything down in some situations. but I am not sure >> if >> there is any other way to do this ? >> >> If not is there a more optimal way to approach the polling I wonder ? > > You could use pushing from the server instead of polling. http://railscasts.com/episodes/260-messaging-with-fayeI''ll add another railscast that appeared a few weeks later that might make implementing a push server even easier: http://railscasts.com/episodes/316-private-pub Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > You could use pushing from the server instead of polling.http://railscasts.com/episodes/260-messaging-with-faye > > I''ll add another railscast that appeared a few weeks later that might > make implementing a push server even easier:http://railscasts.com/episodes/316-private-pub > > Best regards > > Peter De BerdtHi, What is the basic concept here ? Is this standard HTML/Javascript ? Everything in HTTP seems counter to that I have seen, so I am missing something ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Peter De Berdt
2012-Feb-14 13:16 UTC
Re: Re: best approach for ocean ship tracking or similar
On 14 Feb 2012, at 13:10, Jedrin wrote:>>> You could use pushing from the server instead of polling.http://railscasts.com/episodes/260-messaging-with-faye >> >> I''ll add another railscast that appeared a few weeks later that might >> make implementing a push server even easier:http://railscasts.com/episodes/316-private-pub >> > What is the basic concept here ? Is this standard HTML/Javascript ? > Everything in HTTP seems counter to that I have seen, so I am missing > something ?Web technology has advanced quite a bit over the years. One feature of HTML5 is Websockets, which allow a persistent connection with the server and thus allowing the server to push data to the client without any client interaction or workarounds like polling with a certain interval. Frameworks like Faye use Websockets when available and fall back to alternative methods for older browsers (a Flash-based socket or long polling, which is not the same as interval polling). Simply put (it''s actually a bit more complex) the following happens: - User loads the page - Javascript opens a persistent socket to the Faye server (using a named channel if you want it to) - From your Rails app, you send messages to the Faye server, which automatically distributes it to all client connections for that particular channel. The Railscasts explain the concept quite nicely IIRC. Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2012-Feb-14 16:37 UTC
Re: Re: best approach for ocean ship tracking or similar
On Tue, Feb 14, 2012 at 5:16 AM, Peter De Berdt <peter.de.berdt-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> Web technology has advanced quite a bit over the years.Netscape introduced "server push" in 1995, FWIW :-) (Worked fine. Unless you were using MSIE, which of course didn''t support it... ) member, Browser War Veterans Post 408 -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.