My profiler for optimise my script -
HitnKill - 18.07.2013
Hi, i want to optimise my script apparently with my last host my players see other player lag (teleport) with lot of players.
I upload my profiler for you see if my code it's bad on some callback / others...
edit.
Re: My profiler for optimise my script -
ReVo_ - 18.07.2013
What is your OnPlayerUpdate ? It's a very frequent event, keep it fast.
OnPlayerKeyStateChange too.
Mysql_query is threaded not should give problem to your lag.
Re : My profiler for optimise my script -
HitnKill - 18.07.2013
Thanks for your response
My OnPlayerUpdate
PHP код:
public OnPlayerUpdate(playerid)
{
if(EscapeTime[playerid] > 0) EscapeTime[playerid] = 0;
if(PlayerSpawned[playerid] > 0)
{
new Action = GetPlayerSpecialAction(playerid);
if(OPUAction[playerid] != Action) OPUAction[playerid] = Action;
new weapons2 = GetPlayerWeapon(playerid), ammo = GetPlayerAmmo(playerid);
if(pAntiCheat[playerid][LastWeapon] != weapons2) pAntiCheat[playerid][LastWeapon] = weapons2;
if(pAntiCheat[playerid][LastAmmo] != ammo) pAntiCheat[playerid][LastAmmo] = ammo;
}
return 1;
}
This script it's very important for my anti cheat and for my anti c-bug, if i use a timer 100ms or 200ms it's better?
And on OnPlayerKeyStateChange i use a lot of code for my Anti-Cbug or Anti Drive By driver and passenger without driver and others script but i can optimise this.
You think my code on OnPlayerUpdate and OnPlayerKeyStateChange it's too bad?
Re: My profiler for optimise my script -
papedo - 18.07.2013
Often lag reasons:
- Script in OnPlayerUpdate
- A lot of objects or vehicles at one place
- Timers < 500ms
- !! Changing materials or text on objects !!
- frequented asking about player infos GetPlayerPos, Skin, Weapons, Vehicle, Seat.. You can store this serverside, for example create Skin[MAX_PLAYERS] that you will change when you change player skin.. Scripts with variables are much faster than scripts using player getting functions.
AW: My profiler for optimise my script -
BigETI - 18.07.2013
This is a really old script I made once:
http://pastebin.com/TCkpwY3R
It doesn't use OnPlayerUpdate to detect someone "c-bugging".
Re : My profiler for optimise my script -
HitnKill - 18.07.2013
Quote:
Originally Posted by papedo
Often lag reasons:
- Script in OnPlayerUpdate
- A lot of objects or vehicles at one place
- Timers < 500ms
- !! Changing materials or text on objects !!
- frequented asking about player infos GetPlayerPos, Skin, Weapons, Vehicle, Seat.. You can store this serverside, for example create Skin[MAX_PLAYERS] that you will change when you change player skin.. Scripts with variables are much faster than scripts using player getting functions.
|
- I have just 99 objects i think, 350 vehicles.
- My online timer are 1000 ms, just one 30000 ms.
- I d'ont change the materials but i update a label text all 1 second
- Ok thanks for your advice
Quote:
Originally Posted by BigETI
|
My anti c-bug it's good but i use GetPlayerSpecialAction(playerid) for detect on player crouching on OnPlayerUpdate beacause apparently this function it's wrong on OnPlayerKeyStateChange.
https://sampforum.blast.hk/showthread.php?tid=370810
I will improve my anti c bug with your code thanks.
But for my "LastWeapon" on
OnPlayerUpdate it's a bad idea to place it on this callback?
Re: My profiler for optimise my script -
Bakr - 19.07.2013
Your OnPlayerUpdate is not the problem here. It really irritates me that people think putting 20 lines of code inside that callback will completely ruin the server's performance. Those people simply have no clue what they're talking about.
As a reference, GodFather ran relatively stable with 100+ players and it saved every players' stats in OnPlayerUpdate.
Re: My profiler for optimise my script -
xeeZ - 19.07.2013
Quote:
Originally Posted by Bakr
Your OnPlayerUpdate is not the problem here.
|
Did you actually look at the output?
Re: My profiler for optimise my script -
SuperViper - 19.07.2013
Quote:
Originally Posted by xeeZ
Did you actually look at the output?

|
That's after 9625052 calls.
mysql_query and
fclose are the problem. If you use them very often, the server will lag heavily. I recommend switching to threaded queries (R7) and limiting your file function usage. Also, you should highly optimize your
OnPlayerKeyStateChange code because it's being called super often, a little less often than
OnPlayerUpdate.
Re: My profiler for optimise my script -
xeeZ - 19.07.2013
Quote:
Originally Posted by SuperViper
That's after 9625052 calls.
|
It doesn't really matter here how many times it was called, it took ~25% of the time which is more than any other function in the script, so it has to be optimized first.