Multiple Submits
Moderator: General Moderators
-
StormTheGates
- Forum Newbie
- Posts: 4
- Joined: Sat Jul 29, 2006 11:38 pm
Multiple Submits
Hey everyone. I run a text based game and lately I have been having some serious problems. The whole problem stems from my slow server speed. Heres what it is:
Say a user has 1000 dollars. They open up two windows, and on one page go to bank, and on the other go to say roulette. They deposit 1000 dollars into their bank at nearly the exact same time as they bet it on roulette. This has the effect of cloning their money, because it puts it in the bank and bets it at the same time.
I was wondering if anyone had any ideas how to stop this? Right now Iam trying to set a session variable to like 3 seconds, then at the very top of my db connector I check it, and see if they have to wait. I was just wondering what you guys thought?
Say a user has 1000 dollars. They open up two windows, and on one page go to bank, and on the other go to say roulette. They deposit 1000 dollars into their bank at nearly the exact same time as they bet it on roulette. This has the effect of cloning their money, because it puts it in the bank and bets it at the same time.
I was wondering if anyone had any ideas how to stop this? Right now Iam trying to set a session variable to like 3 seconds, then at the very top of my db connector I check it, and see if they have to wait. I was just wondering what you guys thought?
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
You should be deducting the money from the players database entry immediately before you do anything else on the bank or roulette. You might want to place an IF check on the field as well to make sure the value being deducted will not go below 0.
And table locking is messy stuff and can cause the database server to eventually lockup if you are not careful in how you lock and unlock rows. And if the database server is already slow table locking will make it seem even slower. If you want automatic row locking on mysql databases change your database from MYISAM to INNODB. The INNODB format does automatic row locking. This doesn't lock the entire table but locks the row being accessed.
And table locking is messy stuff and can cause the database server to eventually lockup if you are not careful in how you lock and unlock rows. And if the database server is already slow table locking will make it seem even slower. If you want automatic row locking on mysql databases change your database from MYISAM to INNODB. The INNODB format does automatic row locking. This doesn't lock the entire table but locks the row being accessed.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
This is a transactional problem, where a transaction requires multiple selects/updates.
While this can only hurt the player than help them, you've still got the race condition where if they abort before anything else is done, the money deducted will just have disappeared into nothingness.You should be deducting the money from the players database entry immediately before you do anything else on the bank or roulette. You might want to place an IF check on the field as well to make sure the value being deducted will not go below 0.
InnoDB supports transactions. Use them.And table locking is messy stuff and can cause the database server to eventually lockup if you are not careful in how you lock and unlock rows. And if the database server is already slow table locking will make it seem even slower. If you want automatic row locking on mysql databases change your database from MYISAM to INNODB. The INNODB format does automatic row locking. This doesn't lock the entire table but locks the row being accessed.
-
StormTheGates
- Forum Newbie
- Posts: 4
- Joined: Sat Jul 29, 2006 11:38 pm
Hey everyone, thanks for all the awsome responses
.
Iam a real nooblet when it comes to PHP, so what exactly is locking? I figure that it prevents a table from being accessed, but for how long? Because I make multiple SQL queries on one page, and it wont do any good if the thing is locked when I need to update the users money or somesuch.
Iam a real nooblet when it comes to PHP, so what exactly is locking? I figure that it prevents a table from being accessed, but for how long? Because I make multiple SQL queries on one page, and it wont do any good if the thing is locked when I need to update the users money or somesuch.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Read up on it here...StormTheGates wrote:Iam a real nooblet when it comes to PHP, so what exactly is locking? I figure that it prevents a table from being accessed, but for how long? Because I make multiple SQL queries on one page, and it wont do any good if the thing is locked when I need to update the users money or somesuch.
http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Actually that isn't going to be a problem.Ambush Commander wrote:This is a transactional problem, where a transaction requires multiple selects/updates.
While this can only hurt the player than help them, you've still got the race condition where if they abort before anything else is done, the money deducted will just have disappeared into nothingness.You should be deducting the money from the players database entry immediately before you do anything else on the bank or roulette. You might want to place an IF check on the field as well to make sure the value being deducted will not go below 0.
There is only one problem I have with INNODB tables. The amount of memory the tables use when being accessed is many times more than if the table is in MYISAM format. If the tables are LARGE in size you will need a huge amount of system ram to prevent the database from using a lot of swapfile and slowing down the database server. I would only use INNODB tables if the tables are small in size.Ambush Commander wrote:InnoDB supports transactions. Use them.And table locking is messy stuff and can cause the database server to eventually lockup if you are not careful in how you lock and unlock rows. And if the database server is already slow table locking will make it seem even slower. If you want automatic row locking on mysql databases change your database from MYISAM to INNODB. The INNODB format does automatic row locking. This doesn't lock the entire table but locks the row being accessed.
-
StormTheGates
- Forum Newbie
- Posts: 4
- Joined: Sat Jul 29, 2006 11:38 pm
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
I would really like to see how you prevent "money loss" in this example with just programming queries properly. This is a transaction problem and if you don't use one...things gets messy in DB (in your pocket).AKA Panama Jack wrote:Actually that isn't going to be a problem.Ambush Commander wrote:This is a transactional problem, where a transaction requires multiple selects/updates.
While this can only hurt the player than help them, you've still got the race condition where if they abort before anything else is done, the money deducted will just have disappeared into nothingness.You should be deducting the money from the players database entry immediately before you do anything else on the bank or roulette. You might want to place an IF check on the field as well to make sure the value being deducted will not go below 0.I should know our game can allow you to use multiple windows and these things will not happen if you program the queries properly. We do not use table locking because it CAN cause a multitude of problems. We have tried it a multitude of times and every time if the server has moderate usage the database server becomes backed up with queries and everyone trying to access the game starts slowing down. It is definitely not worth the trouble it causes.
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
It has never happened and we can track that in our game.
We have something called extended logging that records every single get and post array each player sends to the server. The code for the bank and casino is very tight. People have definitely tried to fake it out but as I said if you keep things tight and use the proper checks inside the queries you will not have a transactional problem.
can you give me a link of this bank/casino (maybe PM not to be considered Ad)AKA Panama Jack wrote:It has never happened and we can track that in our game.We have something called extended logging that records every single get and post array each player sends to the server. The code for the bank and casino is very tight. People have definitely tried to fake it out but as I said if you keep things tight and use the proper checks inside the queries you will not have a transactional problem.