Make AJAX faster (browser game)

Discussion in 'JavaScript' started by goodidea, Aug 1, 2014.

  1. #1
    For an browsergame I want to make more AJAX calls per second.
    Currently it can do 2-3 AJAX calls per second (including the processing of changing 400 className of div's/updating the map)

    Is it possible to do make it more fast? Or is 2/3 requests/frames really the limit?

    I already checked Comet/WebSockets/Node.JS/Long Polling but they don't increase the speed a lot in my example.

    If you want to see the game and check the problem, send me a message.
     
    goodidea, Aug 1, 2014 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    handshaking response time via http is going to real world best case be around 100ms, average 200ms (five a second) and realistically you could see as much as a full on second per request. There's NOT a lot you can do about it which is why realtime AJAX for things like games is about as useless as AUDIO is when trying to do real-time mixing. It's simply not a viable technology for what you are asking.

    There's a reason most real games are written native or in a byte-code interpreted language like JAVA or .NET (virtual machine my ass), so they can use bi-directional UDP which can be run with no handshaking. Even flash's networking would be better than trying to use AJAX on anything truly time sensitive.

    There's a reason my own efforts with AJAX, CANVAS and AUDIO sent me running and screaming back to FPC with SDL, OpenGL and OpenAL.
     
    deathshadow, Aug 3, 2014 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    I think this is something that have to do with your HTTP server (ex: Apache) settings and browser limitations rather than Ajax (or http requests). This is why if you download files often you notice the connection reset after you hit the 2 download mark.

    Both RFC 2068 and RFC 2616 recommend two simultaneous requests per user for HTTP 1.1:
    Many browsers now a days actually limit it to 4 connections.

    The HTTP server limitation I was referring to is something along the lines of turning off KeepAlive if you have Apache along with other settings (assuming you do not have any mods that further limit connections). This is a good read explaining what keepalive settings does:

    http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html
     
    ThePHPMaster, Aug 3, 2014 IP
  4. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #4
    The problem I encounter with websocket is I can't send data from Chrome to server on Windows 8 machine. I think you can send data faster by compressing raw data as UTF-16 encoding. I can compress UTF-8 data to less than half the original size, but this takes times in the compressing process. It's very fast in decompressing process.
     
    ketting00, Aug 6, 2014 IP