PDA

View Full Version : Lagg (MySQL?)


Siedler
09/10/2011, 02:55 PM
Hey

My Server is lagging when 3-4 players join/disconnect at same time..
I'm using MySQL Plugin from G-StyleZZZ

MySQL Settings

key_buffer = 320M
max_allowed_packet = 320M
thread_stack = 512K
thread_cache_size = 16
query_cache_limit = 100M
query_cache_size = 160M
key_buffer = 64M

Screenshot from gmx

http://img685.imageshack.us/img685/1452/samp786a.png

without MySQL Plugin it's work perfectly

Crystyan12
09/10/2011, 02:59 PM
You use OnPlayerUpdate for players with timer?

Siedler
09/10/2011, 03:00 PM
No i don't use OnPlayerUpdate and not much timer.
It's lagg only with MySQL

Login: 4 Querys
Logout: 2 Querys

Vince
09/10/2011, 03:04 PM
Thread all your queries and you won't have problems.

Siedler
09/10/2011, 03:14 PM
what do you mean with that?

Login
- Check if account exist's
- Check if account is banned (if yes, load ban data)
- Load account data if account isnt banned (1 Query)
- Save to Database, status Online if logged in succesfully.

Logout
- Save Account Data (1 Query)
- Set Status Offline

Vince
09/10/2011, 03:16 PM
http://wiki.sa-mp.com/wiki/MySQL#mysql_query
Read the note that's marked in red.

Siedler
09/10/2011, 03:40 PM
I do not understand what I have to change.


public OnPlayerConnect(playerid)
{
mysql_query("UPDATE 'accounts' SET Status='1' WHERE name='Myname'",THREAD_LOADPLAYER, playerid);
return 1;
}

public OnQueryFinish(query[], resultid, extraid, connectionHandle)
{
switch(resultid)
{
case THREAD_LOADPLAYER:
{
mysql_store_result();
if(IsPlayerConnected(extraid))
{
// ??
}
mysql_free_result();
}
}
return 1;
}

Siedler
10/10/2011, 07:02 AM
Important Note: It's highly recommended to thread all your queries (even INSERT & UPDATE).

What i can Thread here and how? :>

Retardedwolf
10/10/2011, 07:15 AM
What i can Thread here and how? :>

http://forum.sa-mp.com/showthread.php?t=258231

Scroll down to Calgon's post, he will explain.

Siedler
10/10/2011, 08:34 AM
Yes, i know.
But how it work's with INSERT & UPDATE?

Important Note: It's highly recommended to thread all your queries (even INSERT & UPDATE).

It says recommended, but i dont need the callback?

PrawkC
10/10/2011, 09:04 AM
mysql_query(query); // Normal query
mysql_query(query, 1); // Threaded query.

GrimR
10/10/2011, 09:12 AM
So SQL beats flat files how exactly? :).

Never had that kind of problem with basic file access even smashing through heaps of data.

I presume when the OP makes SQL calls they want immediate returns, I thought SQL was supposed to be faster?

Austin
10/10/2011, 09:29 AM
I presume it is a problem with indexing. Try going onto your interface like phpMyAdmin and do a search for a player name in the accounts.

Then add an index on the player name field and try again.

If you have a lot of accounts, the lack of an index (which is essentially a presorted list for referencing), the search can take up to, or over a second. With an index on that column, it'll drop to like 0.001 of a second.

Siedler
10/10/2011, 10:32 AM
before:
0.0820

new with index:
0.0007

Whats now changed?
im added too Threading OnPlayerConnect
hope is fixxed now thanks :>

Austin
10/10/2011, 10:59 AM
If there are still problems, you might want to look at your other tables and whether they need indexes too. Depends what queries you are running.

Like I say, adding an index is basically keeping a pre-ordered list. If you search for "Austin" and the list has no index, it has to go through all of the records looking for me, whereas with the index, you have me at A :),

Siedler
12/10/2011, 03:53 PM
Thread all your queries and you won't have problems.

Hey,

im thread now all querys but on server restart (gmx) ~40 players connect each second, server is crashing.
some ideas? :>