0

In terms of efficiency which is better: maintaining one single long connection with server, or sending multiple instant requests?

I have a web application with multiple interfaces. On one, when user submits data on a web page, it gets sent to the server by ajax query asap, but server cannot send the required answer for some 3-5 seconds. I have 2 ways: the first is to keep querying the server for answer every second; the second is to make server side keep connection alive until it can answer.

Which way is more efficient for the server and which for the client? The design should allow large number of users.

AlexTR
  • 772
  • 8
  • 14
  • 2
    Depends on the use case, and a whole lot of other things, and is probably opinionated. There's another option, using server-sent-events or websockets and push back the answer when available. – adeneo Dec 03 '16 at 15:04
  • The answer should be obvious. If you want to allow large number of users, it's not a good idea to bomb the server with requests. – Charlotte Dunois Dec 03 '16 at 15:04
  • Both options suck. Use websockets. – ceejayoz Dec 03 '16 at 15:08
  • Websockets were not obvious solution for me, ill look into it. Thanks – AlexTR Dec 03 '16 at 15:15
  • 1
    Take a look at [this](http://stackoverflow.com/questions/10028770/in-what-situations-would-ajax-long-short-polling-be-preferred-over-html5-websock) , quite informative – Vinay Dec 03 '16 at 15:20

0 Answers0