Quick question about storing data.

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Quick question about storing data.

Post by crzyone9584 »

Is it better to pull data from a table when a client connects and hold it in a List<> in a small scale ORPG, or should i just update the table every time something changes? I was thinking of limiting the need to connect to the database so much by pulling the last saved information from MySQL then holding it in a List<> on the server for each character. Then x minute intervals save the data to MySQL. Or would it be better to pull/save MySQL every time data is needed on the character?
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Quick question about storing data.

Post by Xaleph »

A persistent object on the server can help reduce database load, but the real question is this: do you need it? If you have 200 players ( it`s a laugh ) or even 1000 people playing simultaneously, is your database showing errors? Does it log exceptions/errors? If the awnser is yes, you might consider changing the database model. If you are absolutely sure the design is good and could not be better optimised then it is now, then yes, maybe you can store "local" objects and flushing them to the database.

The thing is, you don`t need it, correct? If there`s no need: don`t bother. "Premature is the root of all evil" is a famous quote by Donald Knuth. And he`s absolutely right about that. Don`t ever, EVER optimise if it`s not needed. You`ll break things, you spend time and effort on things you don`t need ( yet ) whilst you could spent time working on the actual product, improvements, features, bug reports, hell, even your next game.

Besides, optimization is resource draining on itself. Try it out, I`ve come to the conclusion that Donald was sooo right. I had to create a client/server application once for a weather company, they collected data from over 1200 stations over the world and we got 100b of data every second. Seems the server could only handle 900 at first, so I dugg in trying to solve the issue. I reduced the 100b to 32b but it still wasn`t enough. Weird right? Well, that`s called premature optimization. Turned out there was a concurrency problem on the XML data object from Java that stored too much information leading to buffer overflows. So ( at random ) 3 out of 12 messages where skipped in order for the buffer to work. Installing a new version for Java fixed everything.

Anyway, it`s totally off topic but it shows what it can lead to. I really couldn`t explain the problem. Because Java can do so much more. Getting stuck on something as small as a *#$&#& xml DO is braintwisting.

So in short: no, keep updating that database as much as you want, if you ever run in problems, fix the database first, then start looking at "workarounds."
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Re: Quick question about storing data.

Post by crzyone9584 »

Thanks for the advice. Guess I'm going to go and set up my database now instead of working on creating a List<> to hold the people who are online. Off to get MySQL working securely with C#...
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
Post Reply

Return to “Beginner Help and Support”