24.01.2014, 17:21
Hi,
I've got MySQL working but I find it kinda slow.
Using normal queries or threaded makes no difference when inserting 212 vehicles into a database using a loop.
This code takes about 6 seconds to execute.
It's inside my OnFilterscriptInit callback for now for testing purposes.
The gamemode starts immediately, but shutting it down immediately after starting it takes 6 seconds, due to the queries waiting to be executed.
Also, inside the database, the contents are inserted slowly as well.
If I used
And added GetTickCount() before the loop and after the loop, the result was 5.6 seconds for this loop to execute and starting the server was delayed as well due to non-threaded queries where OnFilterScriptInit had to wait until all queries were processed.
I really thought MySQL would be fast. I find it rather slow, compared to saving the same data into a file.
Inserting this data into MySQL takes 5.8 seconds.
Saving the same data to a file takes only 5 milliseconds (this file is about 42 kilobytes in size and saves 1000 times faster than storing the same data into MySQL).
Executing the format-lines without sending a query takes 1 millisecond.
The output of this is:
Is this normal?
If it is, I might just dump MySQL alltogether.
I got ALOT more data to dump into databases, 212 vehicles is nothing compared to the rest.
This would take several minutes to just store all data into the database.
This is my function to save the same data to a file.
I've got MySQL working but I find it kinda slow.
Using normal queries or threaded makes no difference when inserting 212 vehicles into a database using a loop.
pawn Код:
new Query[600], Disabled;
for (new i; i < sizeof(AVehicleInfo); i++)
{
if (AVehicleInfo[i][VehicleDisabled] == true)
Disabled = 1;
else
Disabled = 0;
format(Query, sizeof(Query), "INSERT INTO VehicleInfo (ID, Name, Class, Price, MaxFuel, Consumption, RefuelTime, Disabled)");
format(Query, sizeof(Query), "%s VALUES ('%i', '%s', '%i', '%i', '%f', '%f', '%i', '%i')", Query,
AVehicleInfo[i][VehicleModel], AVehicleInfo[i][VehicleName], AVehicleInfo[i][VehicleClass], AVehicleInfo[i][VehiclePrice],
AVehicleInfo[i][VehicleMaxFuel], AVehicleInfo[i][FuelConsumption], AVehicleInfo[i][RefuelTime], Disabled);
mysql_function_query(SQL_db, Query, true, "", "");
}
It's inside my OnFilterscriptInit callback for now for testing purposes.
The gamemode starts immediately, but shutting it down immediately after starting it takes 6 seconds, due to the queries waiting to be executed.
Also, inside the database, the contents are inserted slowly as well.
If I used
pawn Код:
mysql_query(SQL_db, Query);
I really thought MySQL would be fast. I find it rather slow, compared to saving the same data into a file.
Inserting this data into MySQL takes 5.8 seconds.
Saving the same data to a file takes only 5 milliseconds (this file is about 42 kilobytes in size and saves 1000 times faster than storing the same data into MySQL).
Executing the format-lines without sending a query takes 1 millisecond.
pawn Код:
new Query[600], Disabled, StartTime, EndTime;
StartTime = GetTickCount();
for (new i; i < sizeof(AVehicleInfo); i++)
{
if (AVehicleInfo[i][VehicleDisabled] == true)
Disabled = 1;
else
Disabled = 0;
format(Query, sizeof(Query), "INSERT INTO VehicleInfo (ID, Name, Class, Price, MaxFuel, Consumption, RefuelTime, Disabled)");
format(Query, sizeof(Query), "%s VALUES ('%i', '%s', '%i', '%i', '%f', '%f', '%i', '%i')", Query,
AVehicleInfo[i][VehicleModel], AVehicleInfo[i][VehicleName], AVehicleInfo[i][VehicleClass], AVehicleInfo[i][VehiclePrice],
AVehicleInfo[i][VehicleMaxFuel], AVehicleInfo[i][FuelConsumption], AVehicleInfo[i][RefuelTime], Disabled);
mysql_query(SQL_db, Query);
// mysql_function_query(SQL_db, Query, true, "", "");
}
EndTime = GetTickCount();
printf("Saving the data to MySQL takes %i milliseconds", EndTime - StartTime);
StartTime = GetTickCount();
for (new i; i < sizeof(AVehicleInfo); i++)
{
if (AVehicleInfo[i][VehicleDisabled] == true)
Disabled = 1;
else
Disabled = 0;
format(Query, sizeof(Query), "INSERT INTO VehicleInfo (ID, Name, Class, Price, MaxFuel, Consumption, RefuelTime, Disabled)");
format(Query, sizeof(Query), "%s VALUES ('%i', '%s', '%i', '%i', '%f', '%f', '%i', '%i')", Query,
AVehicleInfo[i][VehicleModel], AVehicleInfo[i][VehicleName], AVehicleInfo[i][VehicleClass], AVehicleInfo[i][VehiclePrice],
AVehicleInfo[i][VehicleMaxFuel], AVehicleInfo[i][FuelConsumption], AVehicleInfo[i][RefuelTime], Disabled);
}
EndTime = GetTickCount();
printf("Executing the formats takes %i milliseconds", EndTime - StartTime);
StartTime = GetTickCount();
FileVehicleInfo_Save();
EndTime = GetTickCount();
printf("Saving the data to file takes %i milliseconds", EndTime - StartTime);
Код:
Saving the data to MySQL takes 5845 milliseconds Executing the formats takes 1 milliseconds Saving the data to file takes 5 milliseconds
If it is, I might just dump MySQL alltogether.
I got ALOT more data to dump into databases, 212 vehicles is nothing compared to the rest.
This would take several minutes to just store all data into the database.
This is my function to save the same data to a file.
pawn Код:
// This function will save the VehicleInfo datafile
FileVehicleInfo_Save()
{
// Setup local variables
new File:DFile, LineForFile[100];
// Open the VehicleInfo file for writing
DFile = fopen(FileVehicleInfo, io_write);
// Loop through all vehicle-models
for (new Slot; Slot < sizeof(AVehicleInfo); Slot++)
{
fwrite(DFile, "[VehicleModel]\r\n"); // Save the header of this vehiclemodel
format(LineForFile, 100, "VehicleName %s\r\n", AVehicleInfo[Slot][VehicleName]);
fwrite(DFile, LineForFile);
format(LineForFile, 100, "VehicleClass %i\r\n", AVehicleInfo[Slot][VehicleClass]);
fwrite(DFile, LineForFile);
format(LineForFile, 100, "VehicleModel %i\r\n", AVehicleInfo[Slot][VehicleModel]);
fwrite(DFile, LineForFile);
format(LineForFile, 100, "VehiclePrice %i\r\n", AVehicleInfo[Slot][VehiclePrice]);
fwrite(DFile, LineForFile);
format(LineForFile, 100, "VehicleMaxFuel %f\r\n", AVehicleInfo[Slot][VehicleMaxFuel]);
fwrite(DFile, LineForFile);
format(LineForFile, 100, "FuelConsumption %f\r\n", AVehicleInfo[Slot][FuelConsumption]);
fwrite(DFile, LineForFile);
format(LineForFile, 100, "RefuelTime %i\r\n", AVehicleInfo[Slot][RefuelTime]);
fwrite(DFile, LineForFile);
if (AVehicleInfo[Slot][VehicleDisabled] == true)
fwrite(DFile, "VehicleDisabled Yes\r\n");
else
fwrite(DFile, "VehicleDisabled No\r\n");
fwrite(DFile, "[/VehicleModel]\r\n\r\n"); // Save the footer of this vehiclemodel
}
// Close the file
fclose(DFile);
}