open.mp forum
[Pawn] Long callback execution detected (hang or performance issue) - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] Long callback execution detected (hang or performance issue) (/showthread.php?tid=1736)



Long callback execution detected (hang or performance issue) - GospodinX - 2021-03-07

Hi guys



My crash detect log is full with this error



Code:
Long callback execution detected (hang or performance issue)

AMX backtrace:

#0 0082299c in public WoodGrowing () at



(every one minute)

This is a timer that starts every 60 seconds with a loop





Code:
for(new i; i < 2000; i)



I just need to have this loop. How I can improve it to avoid the error.







PHP Code:
#define MAX_WOOD 2000

enum Wood

{

dIDImanja,

Float:dWoodX,

Float:dWoodY,

Float:dWoodZ,

dTime,

dPostavljeno,

dObjd,

dText,

dVrsta,

dHour,

dMin,

dWood,

dProsloMinuta,

dProsloSat,

dUkradeno

};

new 
DI[MAX_WOOD][Wood];

forward WoodGrowing();

public 
WoodGrowing()

{

new 
stringv[128];

new 
vrsta[10];

for(new 
isizeof(DI); i)

{

if(
DI[i][dPostavljeno] == 1)

{

if(
DI[i][dVrsta] == 1) { vrsta "Sljiva"; }

else if(
DI[i][dVrsta] == 2) { vrsta "Kruska"; }

else if(
DI[i][dVrsta] == 3) { vrsta "Jabuka"; }

if(
DI[i][dHour] >= && DI[i][dMin] >= 1)

{

DI[i][dMin] --;

format(stringv,128,"Voce jos nije izraslo !\nVrijeme do izrastanja: %d sati, %d minuta\nVrsta drveca: %s",DI[i][dHour],DI[i][dMin],vrsta);

UpdateDynamic3DTextLabelText(DrvoLabel[i], -1stringv);

}

else if(
DI[i][dMin] == && DI[i][dHour] >= 1)

{

DI[i][dHour] --;

DI[i][dMin] = 60;

format(stringv,128,"Voce jos nije izraslo !\nVrijeme do izrastanja: %d sati, %d minuta\nVrsta drveca: %s",DI[i][dHour],DI[i][dMin],vrsta);

UpdateDynamic3DTextLabelText(DrvoLabel[i], -1stringv);

}

else if(
DI[i][dHour] == && DI[i][dMin] == 0)

{

format(stringv,128,"Voce je izraslo !\nDa oberes voce kucaj/oberivoce\nVrsta drveca:%s",vrsta);

UpdateDynamic3DTextLabelText(DrvoLabel[i], -1stringv);

if(
DI[i][dProsloSat] >= && DI[i][dProsloMinuta] >= 1DI[i][dProsloMinuta] --;

else if(
DI[i][dProsloMinuta] == && DI[i][dProsloSat] >= 1) {

DI[i][dProsloMinuta] --;

DI[i][dProsloSat] = 60;

}

SaveWood(i);

}

}

}

return 
1;





RE: Long callback execution detected (hang or performance issue) - Kwarde - 2021-03-07

https://github.com/Zeex/samp-plugin-crashdetect#configuration

Quote:How long a top-level callback call should last before crashdetect prints a warning. This can be set very high (for example 1000000) to only detect functions that have totally hung, or very low (500) to detect functions that complete, but are just slow (thus affecting overall server execution and sync). Default value is 5000 (5 milliseconds).

Steps to take:



1- Find out how long exactly it takes to execute the code (You could use YSI's profiling: https://github.com/pawn-lang/YSI-Includes/tree/5.x/YSI_Core/y_profiling)

2- Check if commenting out "SaveWood(i);" still creates those errors (if it's writing to files, it could take some time if 2000 woods are being saved)

3- You could use y_iterate instead for looping. Rather than performing 2000 loops every minute you'd just loop through the existing woods



Apart from that, I don't understand the variable names so hard to tell exactly what's what and how it could be improved. Not to mention that not using tabs/spaces (atleast on this forum) makes it harder to read. Spaghetti code if you will.



An alternative would be to change the long_call_time parameter in your server configuration file. However that is pretty much just ignoring the problem -- especially if it hangs pretty long (causing desync and laggs). Otherwise you could slightly increase that value.


RE: Long callback execution detected (hang or performance issue) - Y_Less - 2021-03-07

Or you could make the timer more frequent, which seems counter-intuitive, but means you can do less each one. So instead of doing 2000 items every 60 seconds, to 200 items every 6 seconds (or 20 every 0.6 seconds). That way, even if the code is still slow it's more spread out.