Lag when picking up items or killing NPCs

18 replies [Last post]
Posts: 43

I've noticed that everytime I kill an NPC or pick up an item in the Netgore Demogame (Latest revision at the time of posting this) the Server stops responding for a few seconds and picks back up later.

"Fell too far behind in updates to catch up. Jumping ahead to current time."

It also seems to do this when I log out and the Server is trying to dispose of my account.
Running on Windows 7 64 bit and I am running both the server and the client on the same computer.

And also the Lalt key doesn't seem to be interacting with the world.

Posts: 1691

Just tested and both seem to be working fine for me.

Not sure what to say on the left alt one (what keyboard layout do you use?), but the item one sounds like it might be due to the database. What version of MySQL? Is it hosted locally? Have you changed anything settings-wise from the default values? And what kind of computer/specs?

Posts: 43

I'm currently using Mysql 5.5 64bit, all settings on the server and client are set to revision defaults.
The MySQL server and the Demogame server are both hosted locally

My computer specs:
Duo core 2.70ghz Processor
4 gigs of ram
Nvidia GeForce GT 240 Video card
OS: Windows 7 home premium 64bit

Posts: 1691

Try 5.1.52. MySQL 5.5.x is the development branch, so its highly recommended you don't use that without good reason and knowledge of MySQL.

Posts: 43

sure thing, when I get off work i'll give it a whirl.

Edit: I just went back to MySql version that you suggested and it has helped the problem quite a bit but it hasn't completely gotten rid of it. I'll wait for a few hours and reload from the SVN.

Posts: 1691

Hmm, that is really odd, but it sounds like the problem is pretty much all within the database (or the MySQL .NET connector) so I'm not sure there is anything I can do to "fix" it.

Try the tips for MySQL in the [[performance tuning]] page.

Posts: 164

Make sure your running it as an administrator and turn off UAC. I doubt that has anything to do with it, it probably would stop it/prompt you or something. Doesn't hurt to make sure though. Have you tried this with 2 computers?

Posts: 43

Omnio wrote:
Make sure your running it as an administrator and turn off UAC. I doubt that has anything to do with it, it probably would stop it/prompt you or something. Doesn't hurt to make sure though. Have you tried this with 2 computers?

I disabled UAC quite a while ago on my system
And yea I tested it on my comp with
vista 32 bit
2 gigs ram
duo core 2.3ghz processor
MySql 5.1.52

Still the exact same problems.
When I get the chance, I will try out some of the performance tuning things that Spodi reccomended.

Posts: 1691

Same issue on two different systems? Very odd, since nobody has ever mentioned this problem before.

Posts: 180

I just tried this out with the latest revision as of this post and it does shutter/ lag when attacking npcs, picking up items, killing npcs, and when npcs respawn. It seems like it is lagging because it is writing to the database or the client/server/database/ interaction when items are picked up or when interacting with npcs. I'm not totally sure but it seems possible to me.

Computer:
Windows 7 Ultimate 32bit
2GB of Ram
AMD Athlon 64 X2 Dual Core 2.60GHZ
Ati Radeon x1300
Latest Mysql

Posts: 1691

Can you help me narrow down when this happened? Like, does it happen with the last release (not from SVN)? What if you use the latest MySql .NET connector with the latest release?

Posts: 11

In my past experiences mysql itself is super slow running on Vista or up unless you compile it from source. But this was a while ago and i though they fixed it, starting to doubt that Wink

In my tests a while back, a *nix based mysql server completed requests relatively 10(TEN) times faster than a Vista based mysql server. Back then i was using the wamp mysql. When i recompiled mysql from source i had no such problems. Try recompiling if you have the chance.

I myself am running win7 now and my mysql is still relatively slower than the *nix based one, but i do not have any sensible lag issues as described above.

Posts: 180

I have the latest pretty much everything regarding the MySql.

I haven't really noticed it before but it has happened pretty much throughout all the versions I've tested.

It's not too bad of lag but it is very noticeable.

I thought it was just my video card lagging up but it seems like a database read/write slow down to me.

Posts: 164

Well, time to get that profiler out. (on the server I would assume) That way you might narrow it down a tad and get some more information.

Posts: 11

Mysql has a quite useful setting called "slow query log". It basically records all queries that take longer than X time units.
http://dev.mysql.com/doc/refman/5.0/en/slow-query-log.html - have fun Smile

Posts: 1691

I think I have fixed the issue for the most part. The problem was a combination of a few things. Namely, when you add an item to an inventory, it creates at least one deep copy no matter what. I am thinking of redesigning the logic of it (since it doesn't make too much sense to do that), but its a bit tough.

Combine that with the fact that every item is persistent, and NPCs must recreate their items when they spawn, and the WorldStats stuff, and you got yourself looking at 20+ queries executing for just one NPC death. Brutal.

I am testing something right now that has items not being persistent by default, and they are only set to persistent when added to the possession of a persist object (a persistent character's inventory or equipped items). This got rid of all the database hits for killing a non-persistent NPC, excluding WorldStats stuff. It also makes the deep copy behavior of the inventory not a problem since the deep copy is not persistent by default. So it only makes one query for each slot updated like you would expect.

I am also thinking about doing some more lower-level optimizations. A big improvement that should be relatively safe would be to queue all queries and execute them in the background, making the non-blocking. When you perform a query that reads from the database, it'll have to flush the queue first before performing the read (thus maintaining execution order for queries). Though I am going to have to play around with this one a bit before implementing it, since it could be a bit dangerous. But if it works out like I hope, it would be a huge help since the server doesn't really do a whole lot of database reading.

Though I still find it a bit surprising that the server lags when executing around 30 small queries. So there might be something else that I need to look into before this is fully resolved...

Posts: 180

Only 30 small queries? Are these ran all at once? Maybe it is some limitation of the mysql database itself.

I know registering on a forum which is about 15 queries (IPB3 that is) takes a good amount of time to populate the database.
Maybe something in the default mysql configuration needs changing.

Posts: 1691

Infernal Reaper wrote:
Only 30 small queries? Are these ran all at once?

Well not "all at once" - there is no batching done. But they are run within a very short interval.

Infernal Reaper wrote:
Maybe something in the default mysql configuration needs changing.

I think it might just be a combination of MySQL set up with the default settings (which gives small overhead and has InnoDB tables write after each transaction), having the server and client on the computer (client likes to gobble up the CPU), and that most people probably are using a single "general purpose" HDD. So the HDD seek times are probably the bottleneck.

I just finished implementing the non-blocking query execution interface, and now most queries are running without blocking. Combined with all the other changes I have made to items and the inventory, general in-game combat results in 0 blocking queries and most all queries run are just WorldStats stuff (namely the item creation count). So this shouldn't be a problem anymore. Smile

Posts: 43

Just updated to the latest revision, had a couple of problems with DLL calls but i managed to straighten it out

It was trying to access csfml-graphics and csfml2-graphics.. I replaced all the calls with csfml-graphics-2 and it seemed to straighten it all out

but back on topic...

All database queries seem to be running much faster, my server even hops into the game loop faster. great job spodi!