The only question I have here: Is querying a SQLite database every second for 20 players that bad? I currently cache the values in an array, which is my idea of saving resources. Any ideas?
Try to work with a session array. When a player joins query his kill/deaths and store it by his username in an array. Update it on every kill or death and upload the array content when the player leaves.
Caching is definitely the way to go. Why would you query every second? That's just an overload on resources. And don't do it on the main thread, 20 players/second + querying a database = tons of lag on your server. Caching kill stats? Like when a player is killed? Easy. Create a session that first queries the database when the user joins. Work from this session, and your stats will be updated in the session only. After the player leaves, then update the database, with the information from the session. Then destroy the session. But what happens if the user joined, didn't do anything, and quit? Add an extra value to your session, one that indicates whether or not anything has been changed. If this value is true (or whatever you decide to use to indicate something changed when the player was online), push these updates to the database. But if nothing change, just destroy the session and don't do anything with the database, because nothing changed. An array of session objects sounds like the way to go. @PEMapModder did this for LegionPE's plugin. LBSG also does this. Object-oriented programming ftw!
Oh. So what I did, creating a session object and caching all the stats was right No, I was actually wondering is it THAT bad, but it obviously is now
Why you need query each second? That's totally useless. Instead you can save it when the player leave the server or, if you need the data instantly, you can just update it when the player death or kill someone.
The only problem with updating the database from a cache when a player leaves is that the database won't be updated if the server crashes or segfaults.
That is the point. I never said I actually queried the database every second, since it is obvious that caching is better. But I wanted to know how much better? Yeah. But it is worth it since the servers don't normally crash randomly.