Can someone -
Jay. - 28.05.2011
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.
Re: Can someone -
Gamer_Z - 28.05.2011
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.
Re: Can someone -
Jay. - 28.05.2011
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?
Re: Can someone -
shitbird - 28.05.2011
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.
Re: Can someone -
Vince - 28.05.2011
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++)
Re: Can someone -
linuxthefish - 28.05.2011
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.
Re: Can someone -
Lorenc_ - 28.05.2011
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.
Re: Can someone -
Calgon - 29.05.2011
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.
Re: Can someone -
Jay. - 29.05.2011
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
Re : Can someone -
Naruto_Emilio - 29.05.2011
Use Gamebooster and it will help you for the ram usage