Simple matchmaking/turn system game help

Hi everybody!

I just started developing a turn-based game with corona. I have created a simple game logic that first creates a match using a matchmaking system and then throws the users to another screen with a button, that ends their respective turns when they have taken their respective decissions. I’m having a few drawbacks in the execution:

First off, I’m using corona to develope my game client and a lua based web service to attend my server side. I have two web services, one for the matchmaking system and the other to check whose turn is. The server handles all the data via a mongoDB with JSON namespaces.

The matchmaking simply searches any created game with only one player. If it doesn’t find any searching player then it creates a match with the searching player as the first player, and waits untill another player starts searching. Once a match has been found, the clients show the other screen where the “pass turn” button is. The fist player is marked as the active player, and while one player is active, the other is polling the database for feedback of his turn, then it is notificated to the player via a native.showAlert dialog.

The fact is, that the time it takes to end one player’s turn and send the notification to the other is taking much more than expected in some cases. I have detected that sometimes during execution the servers registers some slow queries (and it really it shouldn’t, I’m querying a very small database with few parameters).

Here is the code to my Turn web service:

function main(web, req) local params = web:params() local msg = "" local cutoff = os.time() + 2 if(params["player"] ~= nil) then if(params["gameID"] ~=nil) then if(params["check"] == "turncheck") then moai.logger:debug("Turn is checked") while os.time() < cutoff do local cursor = mongodb:query('currentGames',{game_id=tonumber(params.gameID),active_player=params.player}) if(cursor:has_more()) then msg = "ctns" break end -- the sleep is put here so you don't hammer the database. posix.sleep(1) end elseif(params["check"] == "turnover") then moai.logger:debug("Turn is over") mongodb:update('currentGames',{game_id=tonumber(params.gameID)},{['$set']={active_player=params.player}},false,false) msg = "ctnn" posix.sleep(1) end end end web:page(json.encode(msg),200,'OK')end[/code]Thanks in advance for your help, it's really much appreciated. [import]uid: 193170 topic_id: 33233 reply_id: 333233[/import]

There are several things going on, and unfortunately most of them are not something that I think most of the Corona Community can help with.

How good is your internet connection? You can check on your computer by going to Speedtest.net and you can get their app for your devices. What are your ping times? Are you getting sufficient bandwidth?

Are you using network.request() or the http socket level stuff to make your app to server queries? Keep in mind the later blocks until it gets it’s data.

After that, you may need to ask your question on appropriate servers.

Is your webserver handling the requests in a timely fashion?
How many queries and how fast?
Typically if the database is complaining about slow queries its because the query itself is taking too long pointing to a database issue. Do you have all the right indexes setup? Do you have any weird join’s going on that would cause MondoDB to not be happy?L

[import]uid: 19626 topic_id: 33233 reply_id: 132086[/import]

Hey Rob, thank you very much for your fast response. I really appreciate it.

I don’t think it could be an internet connection issue, since most of the time I’m getting good times on the requests.

I must say that this is my first project at this scale, and I don’t really know whether the tools or the logic that I’m using are the correct ones.

I am using network.request() to send/recieve (using callbacks) the data to the server. I’m sending the parameters via GET (I’m first trying to understand the logic creating a simple example of what the game will be), and sending back the data in an encoded JSON string.

What do you mean by “Keep in mind the last blocks until it gets it’s data”?

The webserver is the one posted above, it polls the database during 2 seconds and if it finds that it’s the current players turn, it sends a message to the client. If not, the client asks again the webserver. Im only doing one query to the mongoDB and it’s rather simple. There are no joins or complex operations on that query, it simply ask for a register of the currentGames namespace and checks if the asking player is the active one, that’s why I don’t understand why I am getting slow queries in some cases.

Again, thank you very much for your help and your time. [import]uid: 193170 topic_id: 33233 reply_id: 132148[/import]

Blocking is a term that basically means the app stops and waits on the network action to complete before doing anything else. network.request() is an async call which means it runs in the background and your app continues on its merry way until network.request() finishes and interrupts your program with its callback function.

[import]uid: 19626 topic_id: 33233 reply_id: 132173[/import]

There are several things going on, and unfortunately most of them are not something that I think most of the Corona Community can help with.

How good is your internet connection? You can check on your computer by going to Speedtest.net and you can get their app for your devices. What are your ping times? Are you getting sufficient bandwidth?

Are you using network.request() or the http socket level stuff to make your app to server queries? Keep in mind the later blocks until it gets it’s data.

After that, you may need to ask your question on appropriate servers.

Is your webserver handling the requests in a timely fashion?
How many queries and how fast?
Typically if the database is complaining about slow queries its because the query itself is taking too long pointing to a database issue. Do you have all the right indexes setup? Do you have any weird join’s going on that would cause MondoDB to not be happy?L

[import]uid: 19626 topic_id: 33233 reply_id: 132086[/import]

Hey Rob, thank you very much for your fast response. I really appreciate it.

I don’t think it could be an internet connection issue, since most of the time I’m getting good times on the requests.

I must say that this is my first project at this scale, and I don’t really know whether the tools or the logic that I’m using are the correct ones.

I am using network.request() to send/recieve (using callbacks) the data to the server. I’m sending the parameters via GET (I’m first trying to understand the logic creating a simple example of what the game will be), and sending back the data in an encoded JSON string.

What do you mean by “Keep in mind the last blocks until it gets it’s data”?

The webserver is the one posted above, it polls the database during 2 seconds and if it finds that it’s the current players turn, it sends a message to the client. If not, the client asks again the webserver. Im only doing one query to the mongoDB and it’s rather simple. There are no joins or complex operations on that query, it simply ask for a register of the currentGames namespace and checks if the asking player is the active one, that’s why I don’t understand why I am getting slow queries in some cases.

Again, thank you very much for your help and your time. [import]uid: 193170 topic_id: 33233 reply_id: 132148[/import]

Blocking is a term that basically means the app stops and waits on the network action to complete before doing anything else. network.request() is an async call which means it runs in the background and your app continues on its merry way until network.request() finishes and interrupts your program with its callback function.

[import]uid: 19626 topic_id: 33233 reply_id: 132173[/import]