Author Topic: Chat Polling Time  (Read 891 times)

Offline DV8

  • Level 10
  • *
  • Posts: 63
  • Reputation: +0/-0
    • View Profile
    • Shadowrun: Corrosion
Chat Polling Time
« on: March 16, 2011, 11:40:17 AM »
Recently there was a short discussion about optimal chat window polling and unfortunately I can't find the relevant thread any more. Someone posed the question what you were going to do if someone popped out for about an hour, left the browser window open and generated a bunch of needless requests for updates on a chat channel. I'm considering this right now and I'm thinking I should lengthen the time between updates the longer the window has been open and dormant.

So for instance, the first minute you poll once every second. The following 2 minutes you poll once every ten seconds. The following 5 minutes once every 20 seconds. The following 10 minutes once every 30 seconds, etc.

Minute 1: 1/s
Minute 2: 1/10s
Minute 3-5: 1/20s
Minute 6-10: 1/30s
Minute 11-20: 1/60s
Minute 20-40: 1/120s
Minute 41-60: 1/240s
Minute 60+: Just stop...what's the point.

Is this something you guys have had experience with, and if so, how did you solve it?

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: Chat Polling Time
« Reply #1 on: March 16, 2011, 11:48:22 AM »
What about players that are using the chat for a long time? Eventually they'll just see their chat slowing down and finally stop updating even if they're not idle.

I'd rather do something like a chat timeout, where if the user hasn't typed or moved the mouse for > xx minutes, stop polling the chat. Then show a button that the user can press to reconnect to the chat.

Offline CygnusX

  • Level 24
  • *
  • Posts: 303
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Chat Polling Time
« Reply #2 on: March 16, 2011, 11:50:14 AM »
Your timing is a good start, but I believe you'll find that your first step (once per second) will be too hard of a hit for the performance it offers.  You can really get away with once every 2 seconds here (once every 3 if you want to push the envelope).  You can easily tweak this as needed.

I started a php chat project using jquery, then found mibbit and abandoned the idea (too much work for a service I can get for free elsewhere).  I could provide you with at least part of my code if you'd like.  


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Chat Polling Time
« Reply #3 on: March 16, 2011, 11:54:14 AM »
As IRC user I would say never go below 30s. Some/most users just read and do not type anything. They still participate through.

Checking mouse movement for "active reader" detection seems the most reasonable.

Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: Chat Polling Time
« Reply #4 on: March 16, 2011, 12:29:26 PM »
If you use Prototype they already have something like this built into the library called, Ajax.PeriodicalUpdater

I already had my chat coded and running before I discovered Prototype's PeriodicalUpdater so we don't use it but we do use a decay factor in our chat. If users are content with just keeping chat open then they don't need or require up to the second refreshes so we decay there polling 20 seconds for every 2 minutes of inactivity till the polling hits 1 minute, that is the max polling time we go to.

The others are correct 1 second polling intervals will kill a server ;) If you are going to go with polling at that rate make sure you have some sort of blocking mechanism coded into your polling rates. Meaning set a variable called something like block to 1 when you send out your AJAX request, reset it to zero when the request comes back. The biggest thing is to check that block the next time you send out the next request to make sure you got a reply back from the server, if not an internal queue at the browser starts to pile up and bad things happen :) Always remember when JS stuff it doesn't matter how fast your server is (well it does) but you also have to take into consideration the speed of the persons browser/computer/connection is as well :)

Creating online addictions, one game at a time:

Offline chrisjenkinson

  • Level 10
  • *
  • Posts: 61
  • Reputation: +0/-0
    • View Profile
    • Xiphos
Re: Chat Polling Time
« Reply #5 on: March 16, 2011, 01:57:24 PM »
I'm using jQuery for my chat script, and it polls every 5 seconds. If the user changes windows, it closes the chat (detected using the blur() event). This won't handle when someone leaves the chat window open with focus, but there is the mousemove() event which you could check for.

Chris
« Last Edit: March 16, 2011, 02:02:21 PM by chrisjenkinson »

Offline DV8

  • Level 10
  • *
  • Posts: 63
  • Reputation: +0/-0
    • View Profile
    • Shadowrun: Corrosion
Re: Chat Polling Time
« Reply #6 on: March 17, 2011, 04:37:54 AM »
What about players that are using the chat for a long time? Eventually they'll just see their chat slowing down and finally stop updating even if they're not idle.

I was thinking of letting it reset every time you send something. That way, only if you really don't do anything it'll start degrading.

Your timing is a good start, but I believe you'll find that your first step (once per second) will be too hard of a hit for the performance it offers.  You can really get away with once every 2 seconds here (once every 3 if you want to push the envelope).  You can easily tweak this as needed.

Yeah, that's a good point, perhaps 1 second isn't such a hot idea.

Quote
I started a php chat project using jquery, then found mibbit and abandoned the idea (too much work for a service I can get for free elsewhere).  I could provide you with at least part of my code if you'd like.

That would be very much appreciated. I hacked something together myself. It works rather well, but I haven't put it through any aggressive testing yet. Perhaps I can pick up some tips from your code before I do so.

The others are correct 1 second polling intervals will kill a server ;) If you are going to go with polling at that rate make sure you have some sort of blocking mechanism coded into your polling rates. Meaning set a variable called something like block to 1 when you send out your AJAX request, reset it to zero when the request comes back. The biggest thing is to check that block the next time you send out the next request to make sure you got a reply back from the server, if not an internal queue at the browser starts to pile up and bad things happen :)

Good suggestion, I hadn't thought of that. *makes notes*

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal