Why does this work perfect in windows but not in linux? -
_Outbreak_ - 21.04.2011
I'm having trouble saving certain things to my database.
First is properties, and the other is vehicles. I've tested both of the commands in Windows server and they completed in under 1 second with no errors or lag. I tried the same in linux server which my main server runs on, and it lagged the server for a few minutes. Sometimes it completes instantly, but after a few seconds the server crashes.
This is how long it too to complete the task in linus..
[21:57:57]Start
[22:01:13]Finish
This only happens in linux, does anyone see anything wrong with the code below that could be causing this?
pawn Код:
stock SaveVehicles()
{
new DB:Database = db_open(VEHICLES_DB);
new DBResult:result,
query[256];
if(Database)
{
for(new i=1; i<=vTotal; i++)
{
if(VehData[i][vModel] >= 400 && VehData[i][vModel] <= 611)
{
if(VehData[i][Saved] == 1)
{
switch(VehData[i][vType])
{
case TYPE_DEFAULT:
{
VehData[i][vType] = 0;
}
case TYPE_ADMIN:
{
VehData[i][vType] = 1;
}
case TYPE_VIP:
{
VehData[i][vType] = 2;
}
case TYPE_VALLOW:
{
VehData[i][vType] = 3;
}
case TYPE_RESERVED:
{
VehData[i][vType] = 6;
}
}
format(query, sizeof(query), "SELECT `ID` from `vehicles` WHERE `ID`=%d", i);
result = db_query(Database, query);
if(db_num_fields(result))
{
db_free_result(result);
format(query, sizeof(query), "UPDATE `vehicles` SET `ID`=%d,`model`=%d,`xpos`=%f,`ypos`=%f,`zpos`=%f,`angle`=%f,\
`colour1`=%d,`colour2`=%d,`type`=%d,`owner`='%s' WHERE `ID`=%d", i, VehData[i][vModel], VehData[i][VxPos], VehData[i][VyPos],
VehData[i][VzPos], VehData[i][VRot], VehData[i][Colour1], VehData[i][Colour2], VehData[i][vType], VehData[i][Owner], i);
result = db_query(Database, query);
db_free_result(result);
}
else
{
db_free_result(result);
format(query, sizeof(query), "INSERT INTO vehicles(ID,model,xpos,ypos,zpos,angle,colour1,colour2,type,owner)\
values(%d,%d,%f,%f,%f,%f,%d,%d,%d,'%s');", i, VehData[i][vModel], VehData[i][VxPos], VehData[i][VyPos],
VehData[i][VzPos], VehData[i][VRot], VehData[i][Colour1], VehData[i][Colour2], VehData[i][vType], VehData[i][Owner]);
result = db_query(Database, query);
db_free_result(result);
}
savedcars++;
}
}
}
db_close(Database);
}
}
Re: Why does this work perfect in windows but not in linux? -
Alby Fire - 21.04.2011
What's the "vTotal"'s variable value? If it's an high integer that loop might cause lag since your windows server is in hosted on your PC and your linux one is hosted.
And, tell me also where is your database hosted (local or something else)
Re: Why does this work perfect in windows but not in linux? -
_Outbreak_ - 21.04.2011
vTotal is the amount of vehicles, it increases as each vehicle is created. So when i do /savecars, it only saves the vehicles that I've wanted to save using /vsave
I'll try it with MAX_VEHICLES instead, and make a break; once there's no more vehicles to check in the loop.
The database is hosted with the server, its only the vehicles saving and the properties saving that cause the lag. I can save all of the online players files in under a second with no lag at all, and there is much more data involved than there is in the vehicle and property database.
It's weird but this was a lot quicker and had no problems using dini for this, but with the database it's just total lag when trying to save the info.
Re: Why does this work perfect in windows but not in linux? -
Alby Fire - 21.04.2011
Imo there's something wrong with your loop, maybe vTotal has a wrong value and the loop continues...
By the way I've never had a "speed test" with SQLite but should surely be faster than dini.
Re: Why does this work perfect in windows but not in linux? -
_Outbreak_ - 21.04.2011
I did a debug on the database queries, so i could see what was happening. The loop stopped just after the last vehicle. if there's 566 vehicles, vTotal would equal 566. Sometimes it works in under 1 second, which then causes the server to crash a few seconds later.
Re: Why does this work perfect in windows but not in linux? -
Mauzen - 21.04.2011
I guess the SQLite database stuff does not work as it should on linux, or your linux server (vps?) is limiting the hdd/ram access and this causes problems. No idea why the same code shouldnt work on linux, if it is not the database stuff.
Re: Why does this work perfect in windows but not in linux? -
_Outbreak_ - 22.04.2011
Does writing to a SQLite Database use more cpu and RAM usage than dini? It's just the same server and loop were fine with dini, i just thought writing to SQLite database would make things quicker and smoother, since im always trying to iron out any possible lag causes.