MYSQL-Plugin by G-Stylezzz takes lots of CPU!
#1

Hello,
I do not go on. My server takes, since I rewrote the script to MySQL, massive amount of CPU. I cant find an answer, why it is so. I build only once a connection to the MySQL database under "OnGameModeInit". I load Users under OnPlayerLogin like this:

pawn Код:
public OnPlayerLogin(playerid, password[])
{
    MySQLCheck();
    new mysql_row[1024], string2[1024], playername[MAX_PLAYER_NAME], ipaddress[16], string[256];
    GetPlayerIp(playerid, ipaddress, sizeof(ipaddress));
    GetPlayerName(playerid, playername, sizeof(playername));
    format(string2,sizeof(string2),"SELECT * FROM `players` WHERE Name = '%s' AND Password = '%s' LIMIT 1", playername, password);
    mysql_query(string2);
    mysql_store_result();
    if(mysql_num_rows() == 1)
    {
        mysql_fetch_row(mysql_row);
        mysql_fetch_field_row(string2,"Password");
        format(PlayerInfo[playerid][pKey], 128,"%s", string2);
        mysql_fetch_field_row(string2,"PlayerLevel");
        PlayerInfo[playerid][pLevel] = strval(string2);
        mysql_fetch_field_row(string2,"AdminLevel");
        PlayerInfo[playerid][pAdmin] = strval(string2);
        mysql_free_result();
(At the End of this part:
I renamed the OnPlayerUpdate to PlayerRefresh, but it will takes still more than 50% of the CPU. The players only will updated if they disconnect. it looks like (unter OnPlayerDisconnect) this:

pawn Код:
if(IsPlayerConnected(playerid))
    {
        if(gPlayerLogged[playerid])
        {
            MySQLCheck();
            new name[MAX_PLAYER_NAME],  query[MAX_STRING];;
            GetPlayerName(playerid, name, MAX_PLAYER_NAME);
            MySQLUpdatePlayerInt(name,"PlayerLevel", PlayerInfo[playerid][pLevel]);
            MySQLUpdatePlayerInt(name,"AdminLevel", PlayerInfo[playerid][pAdmin]);
(At the end: MySQLUpdatePlayerInt(name,"BannedAdmin", PlayerInfo[playerid][pBannedAdmin]);)
MySQLUpdatePlayerInt contains:
pawn Код:
MySQLUpdatePlayerInt(name[], column[], value)
{
    new query[MAX_STRING];
    format(query,sizeof(query),"UPDATE players SET %s = '%d' WHERE Name = '%s' LIMIT 1", column, value, name);
    mysql_query(query);
}
anybody have an idea, how to fix the cpu-laggs? it can lead to blocking of my server

regards and thanks

/edit: oh, and i forget to say, that the cpu increases, when 1 or more player is connected about 2-10 minutes...
Reply
#2

It is not the MySQL plugin - it's the huge string cells you use.
For example, in the first code that you posted, you used a total of 2048+ cells! You do not need more than 64 for that query.
Reply
#3

Ouh, also i can make it like this:

new mysql_row[64], string2[64], playername[MAX_PLAYER_NAME], ipaddress[16], string[64];

and in the second code:

new name[MAX_PLAYER_NAME], query[64];;

third:
new query[64];

right?
Reply
#4

Let me get this straight:

You made a topic saying "OMGZ MYSQL-Plugin by G-Stylezzz takes lots of CPU! HALP"
Yet in almost the first line of the code you posted I see this:
pawn Код:
mysql_row[1024] string2[1024] string[256];
This lol has made my day.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)