MySQL Problem -
'Pawno. - 18.09.2012
hello.
i had an little problem with my mysql-load/save system.
so, the account loads in ~0-1ms
I tried this:
pawn Код:
stock LoadPlayer(playerid)
{
new count = GetTickCount();
new Query[128], savingstring[40];
format(Query, sizeof(Query), "SELECT * FROM `accounts` WHERE `Name` = '%s'", GetName(playerid));
mysql_query(Query);
mysql_store_result();
while(mysql_fetch_row_format(Query,"|"))
{
mysql_fetch_field_row(savingstring, "Level"); Spieler[playerid][pLevel] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Admin"); Spieler[playerid][pAdmin] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Cash"); Spieler[playerid][pCash] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Tutorial"); Spieler[playerid][pTutorial] = strval(savingstring);
mysql_fetch_field_row(savingstring, "AccountLocked"); Spieler[playerid][pAccountLocked] = strval(savingstring);
mysql_fetch_field_row(savingstring, "SpawnHealth"); Spieler[playerid][pSpawnHealth] = floatstr(savingstring);
mysql_fetch_field_row(savingstring, "Geschlecht"); Spieler[playerid][pGeschlecht] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Skin"); Spieler[playerid][pSkin] = strval(savingstring);
mysql_fetch_field_row(savingstring, "Perso"); Spieler[playerid][pPerso] = strval(savingstring);
}
mysql_free_result();
printf("Account wurde in %d ms geladen.", GetTickCount() - count);
"Account wurde in %d ms geladen" = Account was loaded in .. ms"
The ms shows "0" or "1". this is very good.
but if i save the player (logout/gmx)
it takes up to 40ms.
its too much!
pawn Код:
stock SavePlayer(playerid)
{
if(IsPlayerConnected(playerid))
{
new query[1024];
new count = GetTickCount();
format(query, sizeof(query), "UPDATE `accounts` SET Level=%d, Admin=%d, Cash=%d, Tutorial=%d, AccountLocked=%d, SpawnHealth=%f, Geschlecht=%d, Skin=%d, Perso=%d WHERE Name='%s'",
Spieler[playerid][pLevel],
Spieler[playerid][pAdmin],
Spieler[playerid][pCash],
Spieler[playerid][pTutorial],
Spieler[playerid][pAccountLocked],
Spieler[playerid][pSpawnHealth],
Spieler[playerid][pGeschlecht],
Spieler[playerid][pSkin],
Spieler[playerid][pPerso],
GetName(playerid));
mysql_query(query);
printf("Account wurde in %d ms gespeichert.", GetTickCount() - count);
}
return 1;
}
I use blueG's mysql plugin.
can anyone help me ? :/
Re: MySQL Problem -
mamorunl - 18.09.2012
It looks like you still use the R6 plugin. the R7 plugin uses caching and multi threaded operations so it will load way faster.
However,, 40 ms,, 40 MS! That is nothing. It aint seconds or minutes. Who is complaining about a mere 40 ms...
Re: MySQL Problem -
playbox12 - 18.09.2012
40ms is not to much at all! It's less than 1/10th of a second! I suggest you use threaded queries when loading though, it let's the server focuss on other things whilst processing your request with the mysql server.
For benchmarking I suggest you use the snippet written by Slice (or was it an tutorial, just use ****** or search) however that may not be ideal in this case. It'll tell you how much times the function can execute in one milisecond. Keep in mind this is saving, it has to get all variables from the array, parse them in to a string, and execute the query on the mysql server, threading the query and so updating your mysql plugin to R7 will cut some of that time.
Re: MySQL Problem -
BlackBank - 18.09.2012
This is weird, because i did a test on my Saving script and my saving time was 14ms with the R6 plugin.
My SaveAccount code:
http://pastebin.com/0xBwtiG1
Is your MySQL database on the same SA:MP server (localhost)?
AW: MySQL Problem -
'Pawno. - 18.09.2012
Hm, ok i thought its too high..
@BlackBank3
i have a mysql db on my own pc with xampp.
Re: MySQL Problem -
mamorunl - 18.09.2012
Quote:
Originally Posted by BlackBank3
This is weird, because i did a test on my Saving script and my saving time was 14ms with the R6 plugin.
My SaveAccount code:
http://pastebin.com/0xBwtiG1
Is your MySQL database on the same SA:MP server (localhost)?
|
That is because your code uses the primary key which is indexed. Pawno' uses the playername which is not indexed (I assume) and thus takes more time to look up. If you were to index on a TEXT field it would take even longer.
What I have done in my code is save the userid to a variable since I fetch the rest of the account as well. This method is probably the same as yours and is faster.