12.08.2013, 21:57
Quote:
|
Sorry if I came off as an asshole, I didn't really intend to.
The code you posted, while it is flawed in relative terms, could provide to be decent learning material to go onwards from. I didn't mention input sanitizing, but in case you're either unsure what you're doing or you're going to let an user (or admin) decide about which fields get selected, you surely need to escape the query first (mysql_real_escape_string in most cases). Threaded queries - queries which are executed in another thread, and once they finish, a callback is fired in your main thread - are a good idea since some queries are slower than others. Should a large query be executed while your server has 200 players online, it could even reflect in the server sync and player pings. AKA make things laggy. A few years ago, while I was on vacation, my server was crippled by a wrong INDEX on one of my tables: the more inserts there were, the slower they got, the slower SELECTing got, etc. So this brings me to a few other concepts to try and tackle (and this can take yeaaaaaaaaars to master) such as good database design and scalability. The scalability is something to consider. If a frequent event (once per second per player) on your server sends out 3 queries which are all in the script (main) thread and if every query takes 5 milliseconds to execute, you're going to be in trouble. 3 queries will take 15 milliseconds together, and if you have 200 players online, it means the server should be busy querying 3000 milliseconds per a second, but how is that possible? Now this is a very rough example and in all ways can be avoided, but a-little-better-than-bad planning can avoid issues like this. An example I can bring from my own experience, once again, is a ~300 millisecond delay once a player disconnects. This sadly also went on a production server (fml). So a tip here would be: properly index your tables, take advantage of the vast amounts of RAM your server/computer has (if some data needs to be accessed, depending on its frequency, it may be smart to put it onto the heap, so an array or perhaps dynamically allocate memory using the awesome plugins released by this community) and most important: don't stop learning about stuff. Read interesting articles, tackle realtime problems with your server and its design, read books, whatevs. Time to end this post, wasn't trying to be an asshole, cya |

