Sign in to follow this  

[web] JSP Servlets and eventqueue

This topic is 2855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 javascript 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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this