Ideas for intelligent polling

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Ideas for intelligent polling

Post by Jackolantern »

While Web Sockets solves most of the problems of real-time web-based development, it creates a few more problems itself. First, and most serious, is the fact that Web Sockets move the requirements of the backend off of a web server and to a real, dedicated application server which requires a full, complicated socket server. You will either need to have both a web server and a socket server, or go all sockets, which could become very complicated to emulate things that are basic in HTTP. Comet techniques are really in the same boat, as Comet requires dedicated servers as well.

What I was thinking is trying to find ways to make polling more bandwidth-savvy. For the most part, polling works fine for PBBGs plus it lets you keep it all in the much more simple world of PHP, but it is a huge bandwidth hog compared to sockets (it uses about 1000x more bandwidth by Google's numbers). I think some clever coding could make it a bit more manageable. For example, for chat, on the backend return a value that tells the front end how long it has been since a chat has gone out. Direct the polling to wait longer based on this time, perhaps adding an extra second or two for each 30 seconds that no one has said anything, up to a possible 15 second wait time. A new chat will automatically bring it down to the lowest time again for everyone, which would allow people to respond to what was said. This way the polling will operate quickly to allow back-and-forth conversations, but will slow down to not be wasteful during lulls.

Also if a use of two-way communication is to facilitate other player-to-player interactions (such as PvP), then have the server scan the area the player is in and directs the client to slow down polling if no other players are near the player. If another player enters the area close to the player, the client drops the timer back down on polling to allow for more precise interaction.
The indelible lord of tl;dr
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Ideas for intelligent polling

Post by Xaleph »

Hmm, seems tricky. Especially the PvP part. I have no real experience in PvP in PHP ( wow, you got it? ) however, if I were to make something, I`d have a default interval period, polling only the clients who actually need polling. Most data can be stored in databases, actions taken etcetera. The cooldown should not be more then 2 seconds, otherwise responsiveness is gone. But, I would only update the client every 2 seconds. Maybe store a local action queue on what players are trying to accomplish? Doing the math on the interval? Should be fast to process, add micro timing on the action queue? I don`t know, it`s a tricky situation.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Ideas for intelligent polling

Post by Jackolantern »

It will definitely be tricky, but I think it could be worth it. It definitely depends on the game. If you have live players moving around, you will need to have fast polling pretty much all the time, but there could be some wiggle room for other types of games.
The indelible lord of tl;dr
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: Ideas for intelligent polling

Post by alexander19 »

For my game I've created a turn based pvp system, which used to poll the server every 2 seconds for the players currently fighting, the thing is that if there were about 10 players fighting in the same time, the polling would have failed and the server would block the current players ip for a limited amount of time (I'm on a shared hosting which has a flood security thing going on).
So rather than going with web sokets (which is really out of my league...and out of my pockets lol,considering that 2 dedicated servers are kind of expensive), I'm thinking on trying my luck with flash & AS3.
I saw a lot of games that used flash for their pve/pvp turn based systems, so I guess that flash won't poll the server at a set amount of time but rather query it whenever a player takes any action?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Ideas for intelligent polling

Post by Jackolantern »

Keep in mind that Flash is pretty much 100% sockets. I think they have some lower network capabilities using AMF, and even some communication with PHP, but it is far from being able to run a game on it. Basically all online Flash games use socket servers.
The indelible lord of tl;dr
alexander19
Posts: 180
Joined: Fri Apr 02, 2010 1:05 pm

Re: Ideas for intelligent polling

Post by alexander19 »

Had no ideea that flash uses sockets as well. Guess there arent many options left in this case.
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Ideas for intelligent polling

Post by Xaleph »

Sockets are better then HTTP requests, like AJAX i.c.w. PHP. However, Flash itself sucks, which is why people want to avoid it. Another major issue with flash is that it doesn`t run well on mobile devices ( laptops, mobile phones ) because of the huge power consumtion. The only other option is using a Java Applet which could allow players to maintain a socket. Most computer as well as devices have Java installed, however, applets are generally considered a bad idea, mostly because the developer can get access to the computer. Also, there`s hardly any support left for it. Which is a good thing, imo.

Anyway, the polling question still is a tricky thing. I too believe it`s a tough decision. It depends on the game and more importantly, you`ll never know the load once you`re online. You cannot simulate it, so it`s a rough estimate. It takes time to test and run diagnostics. So, it could work out very well, which would be good, but it could also crash the server if it cannot handle all the load.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Ideas for intelligent polling

Post by Jackolantern »

The Flash power consumption thing is largely hype. Any managed code is going to use a bit more power than native code, and Java is no exception. If Flash content is draining your power, it is due to it using the device's GPU, just like the way native games drain devices (one particular game made with Unreal Mobile drains my iPod Touch in 20 minutes from a full charge lol). With small devices, the CPU is almost constantly fully taxed, so there isn't much more the Flash VM could be doing than that. The hype basically started when Apple declined to allow a Flash player to be ported to the iPhone, citing high power consumption, but I have always felt the reason for that is because Flash delivers a lot of the same content that is in paid apps in the Apple App Store. If they had allowed a Flash player on the iPod, then that would have allowed app developers to circumvent the App Store if they wanted to.

People really don't really avoid Flash, honestly. It is used all over the place, and until HTML5 comes into its own over the next few years, it is a major component of the web, and the leading RIA runtime. Personally, I am lukewarm on Flash development. I prefer the Flex development model a bit more than the basic animation-based Flash platform.

And yes, sockets are better, but it pushes the requirements much higher versus HTTP solutions.
The indelible lord of tl;dr
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Ideas for intelligent polling

Post by Xaleph »

Hehe you are saying that it`s a hype whenever people complain about Flash draining power? I dare you to run a Flash Application on this macBook, and be able to run it for more then 2 hours. I garantuee you my battery will be dead within 2 hours. Faster if it`s a game ( movies are slightly better ). In fact, I used to play a little game called Forest Story ( it`s a farm game hihi ) and I couldn`t run that game for more then an hour. Battery was completely empty.

Oh yes, if I don`t run a flash application ( let`s say I have Ps, NetBeans and FF and Chrome running ) I can easily work 3,5 to 4 hours on this battery.

So, no, it`s not a hype. It`s the simple truth. Flash === power drainage. Oh and yes, it might have something to do with internals and access to GPU, however, that doesn`t mean that it`s NOT flash it`s fault. I can run games for more then 2 hours. I`ll be the first to agree that running games will drain the power more. But honestly, Flash sucks it out of the battery. And I don`t know if the hype started with the iPhone, however, I agree it sure was a big issue contributing to it.

Anyway, it depends on the flash application. Flash games are the biggest issue, RIA/application second, and last are the movies ( youtube, JWplayer)

Oh, and whenever I run something Flash, the temperature rises. Big time. It`s average temperature is around 90 degrees. ( Europe sorry.. )
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Ideas for intelligent polling

Post by Jackolantern »

Hmm..I don't know, maybe Adobe has made Mac Flash Players as an after thought (which could explain some anger from Apple)? My PC laptop has a very good battery gauge that immediately and dynamically changes its life estimation depending on how much power is being pulled, and it doesn't change it at all when I open something in Flash versus just working in Word. Using Flash on here hardly affects my battery at all, nor does it on most Windows computers.
The indelible lord of tl;dr
Post Reply

Return to “General Development”