Using too much CPU...Need help :(
#1

Hey, i've been told my my server providor that my server is using too much CPU.

With 4 players in it was at 9%.

About 5 minutes later, still with 4 players in the server, it was between 10-11%.

Another few minutes later, still with 4 players in, it was at 11-12%

Then with 5 players in it was to 15-16%

About half hour later, there was 7 players in and the CPU usage was 36%

Its constantly creeping up, even if theres the same amount of players in.


I'm really really not sure what could be causing it.

I've deleted a lot of timers, put the timer frequency of some timers higher.

used #define SLOTS 64 (amount of slots the server has) instead of using MAX_PLAYERS


Does anyone have any idea of what kind of things could be causing this?

I've looked through and found some string sizes at 256. When they only really needed to be around 32 or 63, somtimes smaller...

The only problem is when i change tmp[256]; to tmp[64]; or tmp[128];

I get a lot of the same error

Код:
error 047: array sizes do not match, or destination array is too small
So, could anyone tell me firstly what could be causing so much CPU usage, and slowly creeping higher?

And also how i can stop getting the error above?

Thanks
Reply
#2

for the cpu thing
u have any printf variable in your script?
Reply
#3

to the error
pawn Код:
new
  array1[32],
  array2[256];
array1 = array2; // array sizes do not match, or destination array is too small
Reply
#4

print variable? I've got certain thins like. When someone spawns it alerts admins, and it says print(string);

Not sure what you mean though, i've never really used "print" that much.


For the array thing, this is jsut one fo the problems.

pawn Код:
new string[128];
  new idx;
  string = strtok(cmdtext, idx); //Line with error (array sizes do not match, or destination array is too small)

  new tmp[64];
  tmp = strtok(cmdtext, idx);//Line with error (array sizes do not match, or destination array is too small)
The others are on a line wherever 'tmp = strtok(cmdtext, idx);' is present.

They work fine when i change it to 256, but i dont want it that high for things so small.
Reply
#5

Use this version of strtok :
Код:
stock strtok(string[],&idx,seperator = ' ')
{
	new ret[128], i = 0, len = strlen(string);
	while(string[idx] == seperator && idx < len) idx++;
	while(string[idx] != seperator && idx < len)
	{
	  ret[i] = string[idx];
	  i++;
		idx++;
	}
	while(string[idx] == seperator && idx < len) idx++;
	return ret;
}
just change the new ret[128] to a lower if you want. I'd keep it like this, and replace your tmp[256] with tmp[128] and should compile well..

- X Cutter
Reply
#6

Thanks X_Cutter thats fixed the array problem..


Any suggestions on what could be causing the high CPU usage, and slowly creeping higher.


I spoke to one guy, he suggested there could be some functions, with variables that are stacking and not being properly destroyed.

I've looked at my timers, deleted some uselesss ones, and increased the times of some others.

I'm wondering if a more efficient way of handling timers would be to create two timers.

One to handle seconds, the other to handle minutes.
Reply
#7

there is a much better strtok - its double so fast how the from cutter :S
pawn Код:
stock strtok(const string[], &index, const seperator[] = " ")
{
    const size = 30;
    new
        idx = strfind(string, seperator, false, index),
        result[size];
    if(idx == -1)
    {
        if((idx = strlen(string)) > index)
            strmid(result, string, index, idx, size),
            index = idx;
    }
    else if(idx > (index + size - 1))
            strmid(result, string, index, (idx = index + size - 1), size),
            index = idx;
    else    strmid(result, string, index, idx, size),
            index = idx + 1;
    return result;
}
but ... look ****** post
Reply
#8

The thing with the server providor is, we've been given 1 CPU core to ourselves, for our server.

Its a 2x Quad core CPU, and we have 1 core dedicated to our server. Its using a lot, and its not staying stable either, its climbing slowly.

Its not that hes complaining, hes just saying that as it gets higher, sometimes at 90%, the server becomes laggy and people start to time out, which has been happening a lot when theres been 10+ in the server.

i have no experience with sscanf, and very little with dcmd.

Which is better, and where can i find guides on using both?

Is it easy to convert strtok into dcmd or sscanf?
Reply
#9

I can think of 3 possible causes

1. Infinite Looping Timers inside of Infinite Looping Timers.
-Perhaps you set a timer to go off after a timed operation, but it's infinitely looping, so it's running the 2nd timer over and over, which is also infinitely looping. So in it's making more and more timers, and multiplying.

2. Opening multiple Files without closing.
-This was a problem I had with my temporary ban script which would check per minute to see if a player should be unbanned. If you're opening a file and not closing it, it stays open to the server. So opening file after file will eventually build up.

3. Broken loop.
- A mis-typed loop function may not show up in pawno as incorrect, but will just freeze the server.
ex:
pawn Код:
for(new i;loop=15;loop++) // In every loop, 'i' = 15
{
  ....
}

I think 1 is a more possible reason as 2 refers more towards memory.
Reply
#10

There is a fopen and fclose under OnPlayerUpdate.

All fopen must be followed by fclose, before the end of the function?

I'll double check but im sure that part is fine...


I read through the timers discussion topic by ******.

I've noticed i have a lot of timers running together.

For instance. two an every 3 seconds, 3 or 4 ran every 2 seconds. another 2 ran every 10 minutes, and one was running every 5 minutes.

Could that be a main cause in the increasing CPU usage and the timeouts in the server?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)