• 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!

TFS 1.X+ Server performance

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
738
Solutions
9
Reaction score
123
Hello otlanders!

I've made a little script that every second uses the DB as in global event. So my question is, would it lag or even crash the server if there are 50+ players using this global event?

Is there a way to know the performance? a better way to make this?

Lua:
function onThink(interval)
    local players = Game.getPlayers()
    for _, player in pairs(players) do
        if player:getStorageValue(55487) == 1 then
            local maxhp = player:getMaxHealth()
            local hp = player:getHealth()
            local damage = math.floor(( hp * 100 ) / maxhp)
            player:setStorageValue(7890, (100 - damage)/2)
        end
    end
    return true
end

Thank you for your time guys.
 
I asked this question a while back.. What you referring to is often called 'benchmark testing' or 'performance testing'..

The best way is to slap prints with os.time() comparisons before the script runs and after then print the result..
Code:
function onThink(interval)
local startTime=os.time()
    local players = Game.getPlayers()
    for _, player in pairs(players) do
        if player:getStorageValue(55487) == 1 then
            local maxhp = player:getMaxHealth()
            local hp = player:getHealth()
            local damage = math.floor(( hp * 100 ) / maxhp)
            player:setStorageValue(7890, (100 - damage)/2)
        end
    end
local printTime=(os.time()-startTime)
print("Script executed in" .. printTime .. "MS")
    return true
end

You can use other methods to test the load on your server by loggin in test chars on the server.. then using math to calculate it based on a few tests.. 1 players.. 5 players.. 10 players..
The load normally will go up in a pattern and not spiratic.

I suggest making a function to log players in your server. /load or something. If not, you have to do it the old fashioned way of doing an open beta/open alpha/test server/ get players to login/ log mcs in.

You may also watch the amount of % Ram your server utilizes before, during, and after script execution.

I can tell you from experience if you have at least 4 GB of ram.. 50 players.. you probably will not notice any lag from that script.

I hope this helps and i'm not repeating information you already know. :)
Best of luck.
 
Last edited:
To see how much CPU your script consumes, you can use this functions:
Code:
local start = os.clock()
-- your code
print(os.clock() - start)

As for optimizations: you don't need to define those 3 variables: maxhp, hp, damage, cause you can simply do it like this:
Code:
player:setStorageValue(7890, (100 - math.floor(( player:getHealth() * 100 ) / player:getMaxHealth()))/2)

This will decrease readability of your script, but should speed up your script a little.

I asked this question a while back.. What you referring to is often called 'benchmark testing' or 'performance testing'..

The best way is to slap prints with os.time() comparisons before the script runs and after then print the result..
Code:
function onThink(interval)
local startTime=os.time()
    local players = Game.getPlayers()
    for _, player in pairs(players) do
        if player:getStorageValue(55487) == 1 then
            local maxhp = player:getMaxHealth()
            local hp = player:getHealth()
            local damage = math.floor(( hp * 100 ) / maxhp)
            player:setStorageValue(7890, (100 - damage)/2)
        end
    end
local printTime=(os.time()-startTime)
print("Script executed in" .. printTime .. "MS")
    return true
end

You can use other methods to test the load on your server by loggin in test chars on the server.. then using math to calculate it based on a few tests.. 1 players.. 5 players.. 10 players..
The load normally will go up in a pattern and not spiratic.

I suggest making a function to log players in your server. /load or something. If not, you have to do it the old fashioned way of doing an open beta/open alpha/test server/ get players to login/ log mcs in.

I can tell you from experience if you have at least 4 GB of ram.. 50 players.. you probably will not notice any lag from that script.

I hope this helps. :)
Best of luck.

os.time() return time in seconds, so you can't really measure a time for a script that takes less than a second (which this script should do) to execute.
Some workaround is to use os.mtime() which returns time in miliseconds, and is available in some versions of TFS, but not every OTS has this function.
 
I didnt even know about mtime so thanks!
If your server doesnt have mtime you may have os.clock().
Code:
local x = os.clock()
   local s = 0
   for i=1,100000 do s = s + i end
   print(string.format("elapsed time: %.2f\n", os.clock() - x))

Also I forgot to mention if your having trouble getting the players online you can always throw your script in a for loop with the max variable being the amount of players you want to simulate.

Execute the loop more than one time to simulate multiple players but this is not a good method in comparison to having players online..
Test the speed before and after the loop and if you want to see individual time, during each iteration.
 
Last edited:
Well, that helped a lot guys! Really thanks for your time! My host server has 16gb ram with a huge i7, so it shouldnt be a problem. But that will help to get exact data on server process!

again, thank you guys!
 
Back
Top