Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] JSP Servlets and eventqueue

Started by Basiror Feb 20, 2010 at 10:00 AM 3 replies 2.1k views
Original Post
Basiror
Basiror
Hello, I need some advice from experienced web developers. Currently I am working on a browser game using hybrid technology. This is I got a MySQL server, a C++ application and tomcat+jsp It the whole system as follows. client ->JSP -> encode commands as strings -> MySQL command queue(just a innodb table) MySQL command queue -> decode commands -> C++ App -> update MySQL database MySQL database -> JSP -> client(some browser) The problem is the last step, I need to guarantee it is executed after the C++ has updated the MySQL database, otherwise the refreshed page would contain old information and I had to refresh once again. I see only two options a) using AJAX set some timer and then load the actual page content b) since each servlets a threaded, I had to sleep/schedule the servlet thread some time maybe 500 ms a) is an elegant solution but involved a lot of more work and you need &#106avascript on the client side b) on the other hand delaying the servlet is a simple and effective solution What do you think which way should I go?
http://www.8ung.at/basiror/theironcross.html
alucardeck
alucardeck
hi,

just one question..
why use C++ and not Java?

and again, why C++ for something on browser?
Basiror
Basiror
Why not?

I am not using C++ to generate the webpages, thats done with java servlets JSP JSTL ...
The C++ backend just reads in the command queues and handles all the game logic.

I see no reason not to use C++ there.
C++ is my prefered language anyways.

Anyways I decided to use Ajax to load the page content with a tiny delay of 50-100 ms.
http://www.8ung.at/basiror/theironcross.html
alucardeck
alucardeck
well.. exactly because of the delay between Client->Server->Client..

using Java..
you would have a JSP->Java->MySQL->Java->JSP
you dont need to pass by MySQL twice, and also encode strings..


not sure what kind of game you want to do.. but something big with lot of requests per sec would raise the delay a lot..

i am working on a strategy browser-game just like Tribal Wars/ Travian right now.. something like this would destroy my project..
Basiror
Basiror
The world isn t always as easy as it seams.

The reason I use the approach with an event queue is that I need to guarantee the in order execution.

How would you handle all these events otherwise? when the user refreshes his page?

Thats even worse because you unevenly distribute the work over time leading to spikes with lot of work to do.

Imagine a user has 1000 events since his last refresh, you had to handle all these events before you return the latest state .
At peak times this will make your game unplayable.

My archtecture will run pretty smoothly even at peak times since it distributes work over time. And parsing a few hundred strings costs you nothing.


The other advantage of event queues is, you can split them depending on their locality.

Fights taking place in the other half of your game world could be placed in a second event queue effectively halving the work one update process has to perform.

With your setup you have to trigger state updates by user actions which is no option.

All browsergames I know of (space battle games...) use some sort of externally triggered update mechanism.
http://www.8ung.at/basiror/theironcross.html

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.