From b84e2ec16c57e93e0743f73a3fa169036c6ed5dc Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Sat, 13 Apr 2013 10:51:19 -0700 Subject: [PATCH] Increase delay before returning new messages to clients, in an attempt to reduce bandwidth consumption. --- src/net/socialgamer/cah/servlets/LongPollServlet.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/net/socialgamer/cah/servlets/LongPollServlet.java b/src/net/socialgamer/cah/servlets/LongPollServlet.java index 4839888..e5d846a 100644 --- a/src/net/socialgamer/cah/servlets/LongPollServlet.java +++ b/src/net/socialgamer/cah/servlets/LongPollServlet.java @@ -76,6 +76,13 @@ public class LongPollServlet extends CahServlet { */ private static final int MAX_MESSAGES_PER_POLL = 10; + /** + * An amount of milliseconds to wait after being notified that the user has at least one message + * to deliver, before we actually deliver messages. This will allow multiple messages that arrive + * in close proximity to each other to actually be delivered in the same client request. + */ + private static final int WAIT_FOR_MORE_DELAY = 30; + /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ @@ -104,7 +111,7 @@ public class LongPollServlet extends CahServlet { // Delay for a short while in case there will be other messages queued to be delivered. // This will certainly happen in some game states. We want to deliver as much to the client // in as few round-trips as possible while not waiting too long. - Thread.sleep(5); + Thread.sleep(WAIT_FOR_MORE_DELAY); } catch (final InterruptedException ie) { // pass }