Can someone
#1

Hi, my server has been using alot of CPU, it's a download and i'm searching for problems to fix that might be causing it.
I heard loops can be a cause, or a leak? what do they mean by that? Can someone give me an example of a bad loop? or not in use loop, or just bad things that could be causing this.
Reply
#2

If you take a loop you can see maybe some unlimited loops? I have managed to let sa-mp use 2 gb of ram, then my pc crashed.
Reply
#3

Quote:
Originally Posted by gamer_Z
Посмотреть сообщение
If you take a loop you can see maybe some unlimited loops? I have managed to let sa-mp use 2 gb of ram, then my pc crashed.
Erm, I didn;'t really understand much..

pawn Код:
for(new i=0; i <= MAX_PLAYERS; i++)
I've about 18 loops and most of them are the same as the one above, are they bad?
Reply
#4

That basically loops through 500players 18 times. Whether it's healthy/unhealthy as to CPU&RAM usage depends on what you're checking.

Let's say, you're getting the name of a player, and adding [PK] infront of their name.

You're checking "MAX_PLAYERS" which is 500. That means: You're checking 500 player names, and after that: you're adding 4 characters [(1) P(2) K(3) ](4). You're doing that 18 times.
Reply
#5

Quote:
Originally Posted by Funtime
Посмотреть сообщение
pawn Код:
for(new i=0; i <= MAX_PLAYERS; i++)
I've about 18 loops and most of them are the same as the one above, are they bad?
This will cause serious problems, because this loop executes one time too much.
It is a common mistake, and is known as an OBOE (Off-by-one error). The correct equivalent would be:

pawn Код:
for(new i; i < MAX_PLAYERS; i++)
Reply
#6

Remember to re-define your MAX_PLAYERS if you have under 500 maxplayers! This is why you shouldn't set your player limit to high.
Reply
#7

Why not use GetMaxPlayers()
?

I mean loop through your whole server slots not 500 player slots it self.

Maybe using foreach COULD (IDK) COULD help.
Reply
#8

You should read ******' thread on 'code optimisations' to gain an accurate understanding of what might be causing this error for you. Infinite loops might not be your problem, there are many factors to consider adjusting when it comes to optimisation. Click here for a link to said thread.
Reply
#9

Thanks guys, we've managed to reduce the CPU usage with some help here, but theres an even worst problem now.

The CPU may be okay, but the RAM is still increasing, any possibilities of what could be causing the RAM to increase?

Thanks
Reply
#10

Use Gamebooster and it will help you for the ram usage
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)