Is it acceptable to send a MySQL query OnPlayerUpdate?
#1

What the title says, is it acceptable to send a SELECT statement to a MySQL database OnPlayerUpdate?

The purpose of me sending a SELECT statement every player update is to determine in what zone they currently are. Zone coordinates are saved in a MySQL table, so it runs through it to check that.

If this is not recommended at all (which I could imagine because OnPlayerUpdate is sensitive), what would the most performance friendly solution be?
Reply
#2

Much better alternative:

1. Load the zones once (using your SELECT queries etc.) at OnGameModeInit.

2. Install Streamer Plugin

3. Create a dynamic area using CreateDynamicRectangle using the coordinates you just loaded.

4. Use OnPlayerEnterDynamicArea to detect if the player is in the zone (and OnPlayerLeaveDynamicArea) to detect when they leave.

I'm sure you can make it
Reply
#3

OnPlayerUpdate calls roughly 30 times in a second, if you think your MySQL server can handle such load go ahead.

If you can't do it the way admantis said, then atleast make it a fixed one second - looping timer. One query per second is better than 30 per second.
Reply
#4

Cool, I can do that. Thanks for your input, guys!
Reply
#5

Quote:
Originally Posted by Prostilov
Посмотреть сообщение
The purpose of me sending a SELECT statement every player update is to determine in what zone they currently are. Zone coordinates are saved in a MySQL table, so it runs through it to check that.
In programming, theres a thing called "variable". You create it in the script, and then you can use it to store certain data directly in RAM for fast access.
Then theres the "database". It also stores data, but normally isnt accessed directly, but via queries to the database manager. These queries are translated to access some specific data in the database. This process takes a little while. Depending on several details, accessing a database is about 10,000 to 1,000,000 times slower than accessing a variable.
And thats why you should use databases only for the stuff that you really cant store in variables.


Imagine a piece of paper laying in front of you on the desk. You can easily read it, or write on it whatever you like. It would then be a variable. Or you can call your assistant, describe him exactly what piece of paper youre talking about, where to find it, and what to write on it, or what part to read from it. Then you would wait for him to enter the room, find the paper using your descriptions, write to/read from it, leave the room, and call you back to report that hes done with your task. In that case, the piece of paper would be a database.
If you use a database in OnPlayerUpdate, your assistant would have to do this hundreds of times every second. Hed probably quit his job after just a few seconds, or die from exhaustion in 2 minutes. And you couldnt do your own work, because hed constantly be messing around on your desk. And slamming the door at such a high frequency that the slam sounds merge into a seriously annoying beep that pitches up and down as players enter and leave your server.


Just use a global variable and save both your assistant and your nerves.
Код:
new zoneCoordinates[MAX_ZONES][4];
Reply
#6

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
In programming, theres a thing called "variable". You create it in the script, and then you can use it to store certain data directly in RAM for fast access.
Then theres the "database". It also stores data, but normally isnt accessed directly, but via queries to the database manager. These queries are translated to access some specific data in the database. This process takes a little while. Depending on several details, accessing a database is about 10,000 to 1,000,000 times slower than accessing a variable.
And thats why you should use databases only for the stuff that you really cant store in variables.


Imagine a piece of paper laying in front of you on the desk. You can easily read it, or write on it whatever you like. It would then be a variable. Or you can call your assistant, describe him exactly what piece of paper youre talking about, where to find it, and what to write on it, or what part to read from it. Then you would wait for him to enter the room, find the paper using your descriptions, write to/read from it, leave the room, and call you back to report that hes done with your task. In that case, the piece of paper would be a database.
If you use a database in OnPlayerUpdate, your assistant would have to do this hundreds of times every second. Hed probably quit his job after just a few seconds, or die from exhaustion in 2 minutes. And you couldnt do your own work, because hed constantly be messing around on your desk. And slamming the door at such a high frequency that the slam sounds merge into a seriously annoying beep that pitches up and down as players enter and leave your server.


Just use a global variable and save both your assistant and your nerves.
Код:
new zoneCoordinates[MAX_ZONES][4];
Thanks for your advice. I know how to program though but I'm not very familiar with best practices in PAWN, I'm very used to the convenience of Object Oriented programming languages. I've never had much experience working with a database, so I don't know that well what to use it for and what not. Although I will keep in mind what you've said, thanks.

EDIT: I've done what you guys suggested, works very smoothly! I did use y_iterator instead though to store the zones (along with Streamer's dynamic area utility). +REP as soon as I get to a device that doesn't go crazy on these forums.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)