02.09.2017, 10:37
Hello everyone,
I have problem with MySQL. It is very slow while processing queries and while it is processing them it blocks SAMP thread and server seems to be lagging.
In purpose of testing MySQL performance, I made a command SaveAccount which on calling /test I will invoke 500 times to simulate 500 saving accounts. So that is 500 update queries and it takes 15 - 20sec on my PC (i7-4790k, 16gb ram).
What Am I doing wrong? If I don't fix this, server will be always lagging because it can't handle too many queries in second, and imagine 500 players online, and they buy car, gun etc you need to update their status in database.
Please help me how to make MySQL run in different thread which will not make SAMP thread lag.
I am using MySQL plugin R39-6.
Here is the code:
I have also tried to run query inside SaveAccount method with mysql_query and mysql_pquery but result is the same or even worse.
Thanks for help in advance!
I have problem with MySQL. It is very slow while processing queries and while it is processing them it blocks SAMP thread and server seems to be lagging.
In purpose of testing MySQL performance, I made a command SaveAccount which on calling /test I will invoke 500 times to simulate 500 saving accounts. So that is 500 update queries and it takes 15 - 20sec on my PC (i7-4790k, 16gb ram).
What Am I doing wrong? If I don't fix this, server will be always lagging because it can't handle too many queries in second, and imagine 500 players online, and they buy car, gun etc you need to update their status in database.
Please help me how to make MySQL run in different thread which will not make SAMP thread lag.
I am using MySQL plugin R39-6.
Here is the code:
Код:
CMD:test(playerid, params[]) { SCMF(playerid, BLUE, "START TO WRITE WITH - SaveACC4 - 500 times"); for(new i = 0; i < 500; i++) { SaveAccount(playerid); } SCMF(playerid, BLUE, "DONE WITH UPDATING"); return 1; }
Код:
forward SaveAccount(playerid); public SaveAccount(playerid) { if(PlayerInfo[playerid][Level] == 0) return 1; new Pname[24], escpname[24]; GetPlayerName(playerid, Pname, 24); mysql_real_escape_string(Pname, escpname); new Query[1000]; format(Query,sizeof(Query),"UPDATE korisnici SET Novac = '%d', Banka = '%d', Pizza = '%d', Hotdog = '%d', Cigare = '%d'", PlayerInfo[playerid][Novac],PlayerInfo[playerid][Banka],PlayerInfo[playerid][Pizza],PlayerInfo[playerid][Hotdog],PlayerInfo[playerid][Cigare]); format(Query, sizeof(Query), "%s, Utisan = '%d', ZatvorenVreme = '%d', MehanicarOdvoz = '%d', MobKredit = '%d', Sladoled = '%d'", Query,PlayerInfo[playerid][Utisan],PlayerInfo[playerid][ZatvorenVreme],PlayerInfo[playerid][MehanicarOdvoz],PlayerInfo[playerid][MobKredit],PlayerInfo[playerid][Sladoled]); format(Query, sizeof(Query), "%s, Kazne = '%d', Materijali = '%d', GunMatsi = '%d', Droga = '%d', Zavisnost = '%d'", Query,PlayerInfo[playerid][Kazne],PlayerInfo[playerid][Materijali],PlayerInfo[playerid][GunMatsi],Dzep[playerid][Droga],PlayerInfo[playerid][Zavisnost]); format(Query, sizeof(Query), "%s, GunProdano = '%d', Level = '%d', Iskustvo = '%d', Meta = '%d', CijenaGlave = '%d'", Query,PlayerInfo[playerid][GunProdano],PlayerInfo[playerid][Level],PlayerInfo[playerid][Iskustvo],PlayerInfo[playerid][Meta],PlayerInfo[playerid][CijenaGlave]); format(Query, sizeof(Query), "%s, PayDayPoeni = '%d', Minonl = '%d', Sationl ='%d', PosaoUgovor = '%d', TimUgovor = '%d'", Query,PlayerInfo[playerid][PayDayPoeni],PlayerInfo[playerid][Minonl],PlayerInfo[playerid][Sationl],PlayerInfo[playerid][PosaoUgovor],PlayerInfo[playerid][TimUgovor]); format(Query, sizeof(Query), "%s, KaznaUgovor = '%d', PreostaloZaOtplatu = '%d', RKuca = '%d'", Query,PlayerInfo[playerid][KaznaUgovor], PlayerInfo[playerid][PreostaloZaOtplatu],PlayerInfo[playerid][RKuca]); format(Query, sizeof(Query), "%s WHERE ID = '%d'",Query,PlayerInfo[playerid][BazaID]); mysql_tquery(MySQL, Query, "OnTHREAD_UPDATEACCOUNT", "d", playerid); return 1; }
Код:
forward OnTHREAD_UPDATEACCOUNT(playerid); public OnTHREAD_UPDATEACCOUNT(playerid) { return 1; }
Thanks for help in advance!