SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 04/12/2019, 06:56 PM   #1
CoCo06
Little Clucker
 
Join Date: Nov 2013
Posts: 11
Reputation: 0
Default High CPU Usage

Hello! My server has a 80-90% cpu usage with about 70-90 players online. That's huge, but I can't understand why. I decided to run the server with the profiler plugin and I completely erased 3 functions with the highest Total Time(around 70%, given by the profiler plugin). However, the CPU Usage is the same, maybe 2-3% lower.
I ran the profiler plugin again, and this is the output, after 43 hours with around 70(+/- 30) players: https://www.dropbox.com/s/415rlawh8r...iler.html?dl=0
Sorted(overall total time): https://i.imgur.com/4geVCMH.jpg
I also erased everything under OnPlayerUpdate and I optimized CustomPickups and SetPlayerUnjail functions, but I doubt this will help, as I said, I have already erased 3 functions with a bigger total time and I see no result.

I use the following plugins: mysql.so hash.so profiler.so
So, what else can I do to decrease the cpu usage?
CoCo06 is offline   Reply With Quote
Old 04/12/2019, 11:41 PM   #2
Danbo7
Little Clucker
 
Join Date: Nov 2019
Posts: 21
Reputation: 0
Default Re: High CPU Usage

What timers do you have running? Do any of your timers connect to mysql
Danbo7 is offline   Reply With Quote
Old 05/12/2019, 05:15 AM   #3
CoCo06
Little Clucker
 
Join Date: Nov 2013
Posts: 11
Reputation: 0
Default Re: High CPU Usage

I have around 12 global timers, only 2 of them are at 1000ms interval, both with a loop through all connected players, in which I only set some values and update some textdraws when needed. The other timers have a bigger interval(10s or more) and are only used for server messages, events like trivia and other small things like this.
The only timer that is connected to mysql is set at 30 minutes interval and I use it to save the accounts, with threaded queries.
For player cooldown(like "you can use this command in x seconds") i use unix timestamp.

However, when i need some timers to repeat only a few times, i use something like this(let's say i want to call "function" 10 times, at 500ms interval):
Code:
//start timer: 
function(1);

public function(cnt)
{
// things to do here
if(cnt < 10) SetTimerEx("function", 500, false, "i", cnt+1);
}
Is it a problem because I create more timers, even if only one is running at a moment?
CoCo06 is offline   Reply With Quote
Old 05/12/2019, 03:52 PM   #4
Politis
Little Clucker
 
Politis's Avatar
 
Join Date: Nov 2016
Location: Los Santos
Posts: 17
Reputation: 0
Default Re: High CPU Usage

Try to find which script is using that much CPU. If this won't solve it, if you hosted your server from a site, try to increase the CPU (buy more or something). If you own a rak, upgrade the CPU.
__________________
Politis is offline   Reply With Quote
Old 05/12/2019, 05:47 PM   #5
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,902
Reputation: 1321
Default Re: High CPU Usage

You have 4 culprits.

One callback and three functions.

- Callback post all OnPlayerUpdate() code for review
- Post this function PlayerToPoint()
- Post all timer code for per-player / repeating timers
- Look for loops using PlayerToPoint(), floatsub(), and IsPlayerInRangeOfPoint() post all code
Pottus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
High CPU usage, please help me Hillo Scripting Help 6 23/08/2019 01:02 AM
cpu high usage TheWhiteEarth Server Support 5 16/02/2014 12:43 PM
High CPU Usage CONTROLA Scripting Help 1 23/09/2013 07:34 PM
High CPU Usage jop9888 Scripting Help 0 21/07/2012 08:31 PM
High RAM usage Pooh7 Server Support 7 12/02/2012 09:49 PM


All times are GMT. The time now is 05:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.