• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Linux High CPU Usage

_Aion_

Nothing Else
Joined
Jan 19, 2010
Messages
400
Solutions
4
Reaction score
10
Location
Jequie,Bahia,Brazil
Hello, someone know how to solve "high cpu usage"?
My CPU is 100-120% and causing lag...
I trying all that i know(few things).
I'm using OTX 2.9(last version), my config is 8GB RAM, 4VCPU.
80-100 players online, MAP 42MB.

I think that is something in "spells", but no sucess...
I dont know how solve.
 
Any custom spells from you or OTX, if yes post the codes.
Tried TFS?
Tried a default OTX datapack?
 
Hello, someone know how to solve "high cpu usage"?
My CPU is 100-120% and causing lag...
I trying all that i know(few things).
I'm using OTX 2.9(last version), my config is 8GB RAM, 4VCPU.
80-100 players online, MAP 42MB.

I think that is something in "spells", but no sucess...
I dont know how solve.
The only other option if you don't know if you have custom scripts or source edits is to post the entire project but that is asking a lot of you. You should try as @WibbenZ suggested a clean TFS build and see if the issue persists. If it does then you should be looking for hosting elsewhere.
 
There is most likely nothing wrong with the dedicated server itself (rarely is), and I don't think his playerbase would be too eager to play on a server that uses the default OTX datapack (even if temporarily).

Here are a few suggestions (for now):

  • Install a profiling tool (preferably perf). This will help you analyze the OTX process and determine what function calls hogs the CPU.
  • Use a different build type, i.e. RelWithDebInfo instead of Release.
  • Things to look out for: Infinite Loops, Inappropriate usage of addEvent(s) & Too fast Attack Speed.
 
Any custom spells from you or OTX, if yes post the codes.
Tried TFS?
Tried a default OTX datapack?
Yes, I tried TFS 0.4 and my OTX is Clean.
My spells are based on this
Lua:
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_HITCOLOR, COLOR_TEAL)
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
--setCombatParam(combat1, COMBAT_PARAM_EFFECT, 40)
setCombatParam(combat1, COMBAT_PARAM_DISTANCEEFFECT, 156-1)
--setCombatFormula(combat1, COMBAT_FORMULA_LEVELMAGIC, -40.0, 0, -41.5, 0)

function onTargetCreature(cid, target)
    if not isPlayer(cid) then return true end min = (getPlayerLevel(cid) * 5 + getPlayerMagLevel(cid) * 50) * 6
         doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -min, -min, CONST_ME_BLOCKHIT)
     return true
end
setCombatCallback(combat1, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")

local function onCastSpell1(parameters)
return isPlayer(parameters.cid) and doCombat(parameters.cid, combat1, parameters.var)
end

function onCastSpell(cid, var) if BlockSpellsInArea(cid) then doPlayerSendCancel(cid, "Não pode usar Spells neste local..") return false end
    if exhaustion.check(cid, 0010) == TRUE then
        doPlayerSendCancel(cid, "You are exhauted.")
        doSendMagicEffect(getCreaturePosition(cid), 2)
        return false end
local parameters = {cid = cid, var = var, combat1 = combat1}

for k = 1, 10 do
    addEvent(function()
        if isCreature(cid) then
            addEvent(onCastSpell1, 1, parameters)
            exhaustion.set(cid, 0010, 1.25)
        end
    end, 1 + ((k-1) * 225))
end
return true
end
There is most likely nothing wrong with the dedicated server itself (rarely is), and I don't think his playerbase would be too eager to play on a server that uses the default OTX datapack (even if temporarily).

Here are a few suggestions (for now):

  • Install a profiling tool (preferably perf). This will help you analyze the OTX process and determine what function calls hogs the CPU.
  • Use a different build type, i.e. RelWithDebInfo instead of Release.
  • Things to look out for: Infinite Loops, Inappropriate usage of addEvent(s) & Too fast Attack Speed.
My server have "fast attack", i will remove this and try.
But, when i remove all spells CPU stay between 20-40%
 
This section is frightening
Lua:
for k = 1, 10 do
    addEvent(function()
        if isCreature(cid) then
            addEvent(onCastSpell1, 1, parameters)
            exhaustion.set(cid, 0010, 1.25)
        end
    end, 1 + ((k-1) * 225))
end
You are calling onCastSpell1 instantly 10 times per cast and setting the same exhaust, this piece of code is the timer? 1 + ((k-1) * 225)
Code:
1 + ((k-1) * 225)
-- when k equals 1
1-1 = 0 x 225 + 1 = 1
2-1 = 1 x 225 + 1 = 226
etc..
 
This section is frightening
Lua:
for k = 1, 10 do
    addEvent(function()
        if isCreature(cid) then
            addEvent(onCastSpell1, 1, parameters)
            exhaustion.set(cid, 0010, 1.25)
        end
    end, 1 + ((k-1) * 225))
end
You are calling onCastSpell1 instantly 10 times per cast and setting the same exhaust, this piece of code is the timer? 1 + ((k-1) * 225)
Code:
1 + ((k-1) * 225)
-- when k equals 1
1-1 = 0 x 225 + 1 = 1
2-1 = 1 x 225 + 1 = 226
etc..
I.dont know what is *225.
I Find this script on folder and reproduce.
Its give 10 hits in few time and another give 3, 5, 7.
17 hits in 1 second?
 
I.dont know what is *225.
I Find this script on folder and reproduce.
Its give 10 hits in few time and another give 3, 5, 7.
17 hits in 1 second?
Try this on for size.
Lua:
local iterations = 10
local exhaustTime = 1.25 * iterations

-- you should edit the return value keeping "i" in formula
function castTimer(i)
    return 1 + ((i-1) * 225)
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_HITCOLOR, COLOR_TEAL)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 156-1)
function onTargetCreature(cid, target)
    if not isPlayer(cid) then
        return true
    end
    min = (getPlayerLevel(cid) * 5 + getPlayerMagLevel(cid) * 50) * 6
    doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -min, -min, CONST_ME_BLOCKHIT)
    return true
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
local function castSpell(x)
    if isPlayer(x.cid) then
        -- delete the event from the event table
        -- as soon as we execute this section of the script
        x.event[x.counter] = nil
        return doCombat(x.cid, x.combat, x.var)
    end
    -- make an attempt to stop the events if the player is no longer online or dead
    if next(x.event) then
        for n, event in pairs(x.event) do
            if x.event[n] then
                -- stop the event if its stored
                stopEvent(event)
                x.event[n] = nil
            end
        end
    end
    return false
end
function onCastSpell(cid, var)
    if BlockSpellsInArea(cid) then
        doPlayerSendCancel(cid, "Não pode usar Spells neste local..")
        return false
    end
   
    if exhaustion.check(cid, 0010) == TRUE then
        doPlayerSendCancel(cid, "You are exhauted.")
        doSendMagicEffect(getCreaturePosition(cid), 2)
        return false
    end
   
    p = {cid = cid, var = var, combat = combat, event = {}, counter = 0}
    exhaustion.set(cid, 0010, exhaustTime)
    for k = 1, iterations do
        addEvent(function()
            if isCreature(cid) then
                p.counter = k
                p.event[k] = addEvent(castSpell, 1, p)
            end
        end,
        castTimer(k))
    end
    return true
end
 
Try this on for size.
Lua:
local iterations = 10
local exhaustTime = 1.25 * iterations

-- you should edit the return value keeping "i" in formula
function castTimer(i)
    return 1 + ((i-1) * 225)
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_HITCOLOR, COLOR_TEAL)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 156-1)
function onTargetCreature(cid, target)
    if not isPlayer(cid) then
        return true
    end
    min = (getPlayerLevel(cid) * 5 + getPlayerMagLevel(cid) * 50) * 6
    doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -min, -min, CONST_ME_BLOCKHIT)
    return true
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
local function castSpell(x)
    if isPlayer(x.cid) then
        -- delete the event from the event table
        -- as soon as we execute this section of the script
        x.event[x.counter] = nil
        return doCombat(x.cid, x.combat, x.var)
    end
    -- make an attempt to stop the events if the player is no longer online or dead
    if next(x.event) then
        for n, event in pairs(x.event) do
            if x.event[n] then
                -- stop the event if its stored
                stopEvent(event)
                x.event[n] = nil
            end
        end
    end
    return false
end
function onCastSpell(cid, var)
    if BlockSpellsInArea(cid) then
        doPlayerSendCancel(cid, "Não pode usar Spells neste local..")
        return false
    end
  
    if exhaustion.check(cid, 0010) == TRUE then
        doPlayerSendCancel(cid, "You are exhauted.")
        doSendMagicEffect(getCreaturePosition(cid), 2)
        return false
    end
  
    p = {cid = cid, var = var, combat = combat, event = {}, counter = 0}
    exhaustion.set(cid, 0010, exhaustTime)
    for k = 1, iterations do
        addEvent(function()
            if isCreature(cid) then
                p.counter = k
                p.event[k] = addEvent(castSpell, 1, p)
            end
        end,
        castTimer(k))
    end
    return true
end
I will try.

Try this on for size.
Lua:
local iterations = 10
local exhaustTime = 1.25 * iterations

-- you should edit the return value keeping "i" in formula
function castTimer(i)
    return 1 + ((i-1) * 225)
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_HITCOLOR, COLOR_TEAL)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 156-1)
function onTargetCreature(cid, target)
    if not isPlayer(cid) then
        return true
    end
    min = (getPlayerLevel(cid) * 5 + getPlayerMagLevel(cid) * 50) * 6
    doTargetCombatHealth(cid, target, COMBAT_PHYSICALDAMAGE, -min, -min, CONST_ME_BLOCKHIT)
    return true
end

setCombatCallback(combat, CALLBACK_PARAM_TARGETCREATURE, "onTargetCreature")
local function castSpell(x)
    if isPlayer(x.cid) then
        -- delete the event from the event table
        -- as soon as we execute this section of the script
        x.event[x.counter] = nil
        return doCombat(x.cid, x.combat, x.var)
    end
    -- make an attempt to stop the events if the player is no longer online or dead
    if next(x.event) then
        for n, event in pairs(x.event) do
            if x.event[n] then
                -- stop the event if its stored
                stopEvent(event)
                x.event[n] = nil
            end
        end
    end
    return false
end
function onCastSpell(cid, var)
    if BlockSpellsInArea(cid) then
        doPlayerSendCancel(cid, "Não pode usar Spells neste local..")
        return false
    end
  
    if exhaustion.check(cid, 0010) == TRUE then
        doPlayerSendCancel(cid, "You are exhauted.")
        doSendMagicEffect(getCreaturePosition(cid), 2)
        return false
    end
  
    p = {cid = cid, var = var, combat = combat, event = {}, counter = 0}
    exhaustion.set(cid, 0010, exhaustTime)
    for k = 1, iterations do
        addEvent(function()
            if isCreature(cid) then
                p.counter = k
                p.event[k] = addEvent(castSpell, 1, p)
            end
        end,
        castTimer(k))
    end
    return true
end
Same issue.
How i use perf to look the fuction that "eat" my CPU?
 
Last edited by a moderator:
Same issue.
How i use perf to look the fuction that "eat" my CPU?
Have you installed perf onto your system? If you haven't already, please visit the following link: How to install "perf" monitoring tool?. Please keep in mind that the package tool might be unable to find the appropriate packages (One reason could be that your server uses a custom kernel).

Once installed you can try using perf top to see the overall usage (Tutorial - Perf Wiki):
Code:
$ sudo perf top

Here is an image of how it may look:
q97zoTt.png


 
Last edited:
If all your spells are based on loops, as 2Rec just said, it's obviously going to lag and you need to check it. They're probably giving errors too in the console?
 
If all of your spells are based on that, you gotta revise them all obviouosly.
Yes, but I do not know how to "review" or do not use much looping.
If all your spells are based on loops, as 2Rec just said, it's obviously going to lag and you need to check it. They're probably giving errors too in the console?
I previously showed the following "creature not found" error, but I modified a line by adding "if IsPlayer ()" and stopped showing the errors in the console
 
Its the multiple calls your spell's code is making each time a spell is cast. Like all said above, if all your spells or even a few popular spells are written in the same manner, your playerbase is using up a significantly larger portion of computing power than necessary. Removing all spells and noticing a 90% drop in CPU usage is also a heavy hint in this direction. They gotta be optimized, bruh.
 
Its the multiple calls your spell's code is making each time a spell is cast. Like all said above, if all your spells or even a few popular spells are written in the same manner, your playerbase is using up a significantly larger portion of computing power than necessary. Removing all spells and noticing a 90% drop in CPU usage is also a heavy hint in this direction. They gotta be optimized, bruh.
Yes. But i dont know how i will optmize this spells.
When i remove all spells, CPU stay 2-15% with 70 online.
 
Back
Top