Raised This Month: $32 Target: $400
 8% 

Ensure saving cached data to database?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-12-2015 , 06:27   Ensure saving cached data to database?
Reply With Quote #1

So I want to save a stat related to a player to a database and have these stats cached for each player as well, sort of like clientprefs.

The stats are cached so my plugin natives can return the data instantly instead of having to wait for a SQL callback to read the data.

The stats don't change often or frequently, it might be once a day and if you max out every stat then it's all done for that player, but I want to ensure a scenario doesn't happen where you have to repeat a level up.

Let's say my site goes down (the database goes down), how do I handle making sure the cached stat for this player will eventually be saved?

Using threaded queries of course.


My first thought was to just make a file on the server saying what to send when the database goes back up.
__________________

Last edited by Chdata; 12-12-2015 at 06:57.
Chdata is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 12-12-2015 , 07:57   Re: Ensure saving cached data to database?
Reply With Quote #2

Use both sqlite and mysql at once, and use sqlite as a temporary dump or something if your site goes down?
Potato Uno is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-13-2015 , 05:17   Re: Ensure saving cached data to database?
Reply With Quote #3

Hm.

Since it's more or less an unlocks system (the player unlocks things) that's also for fun, I also have the option of just disabling it if the database is down, which probably will only rarely happen anyway.
__________________
Chdata is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-19-2015 , 05:28   Re: Ensure saving cached data to database?
Reply With Quote #4

After reading the wiki about SQL:

"Since SQLite is local only, most of the connection parameters can be ignored."

Does this mean for SQLite database functions it simply works as read/write to a file with no possibility of disconnecting?

Should SQLite queries still be threaded to avoid lag, or will non-threaded still work without lag?
__________________

Last edited by Chdata; 12-19-2015 at 05:30.
Chdata is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-19-2015 , 13:01   Re: Ensure saving cached data to database?
Reply With Quote #5

Quote:
Originally Posted by Chdata View Post
After reading the wiki about SQL:

"Since SQLite is local only, most of the connection parameters can be ignored."

Does this mean for SQLite database functions it simply works as read/write to a file with no possibility of disconnecting?

Should SQLite queries still be threaded to avoid lag, or will non-threaded still work without lag?
They do, If you want to write a lot of stuff on it or just read a non-indexed 60mb+ DB. Why not just using threaded queries, they are not that difficult to implement
fakuivan is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 12-19-2015 , 15:06   Re: Ensure saving cached data to database?
Reply With Quote #6

SQLite will work forever as it's local. You would need to lose access to the disk srcds is living on to lose connection to SQLite (which, if that happens, you have bigger problems lol).

It's a read/write to a file. You should still use threaded queries even though non-threaded works pretty fast, because if the I/O queue is jammed then the server will lag if it's non-threaded. The I/O time is the lag for sqlite.
Potato Uno is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 12-19-2015 , 16:50   Re: Ensure saving cached data to database?
Reply With Quote #7

alright. but at least it doesn't die.

Can a single plugin do two db connections at once? I seem to recall that one plugin can only open one connection at a time, but I forgot where I read that.
__________________

Last edited by Chdata; 12-19-2015 at 16:52.
Chdata is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-19-2015 , 17:03   Re: Ensure saving cached data to database?
Reply With Quote #8

Quote:
Originally Posted by Potato Uno View Post
SQLite will work forever as it's local. You would need to lose access to the disk srcds is living on to lose connection to SQLite (which, if that happens, you have bigger problems lol).

It's a read/write to a file. You should still use threaded queries even though non-threaded works pretty fast, because if the I/O queue is jammed then the server will lag if it's non-threaded. The I/O time is the lag for sqlite.
But if the queue is saturated all the time the plugin will crash anyway, as Potato Uno found out the hard way.

Last edited by fakuivan; 12-19-2015 at 17:13.
fakuivan is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-19-2015 , 17:13   Re: Ensure saving cached data to database?
Reply With Quote #9

Quote:
Originally Posted by Chdata View Post
alright. but at least it doesn't die.

Can a single plugin do two db connections at once? I seem to recall that one plugin can only open one connection at a time, but I forgot where I read that.
afik yes, you can, write the stats to the sqlite and to the mysql at the same time, then update the mysql when your site goes up again.
fakuivan is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:45.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode