I am trying to do some simple logging of ms between each server heartbeat and I have found that it has a really big spike on heartbeat number 7 or 8 and I cannot understand why exactly 7 or 8. I cannot find any reason for the printing to be the reason or any large actions happening on that heartbeat compared to any of the others.
I have a script that will store the last x (list_len variable) amount of ms between two heartbeats and after reaching that amount it will print all the times between heartbeats and also the highest plus the second highest. With this I see that the second highest doesn’t even come close to the highest and that the highest is always indexed at 7 or 8.
local RUN = game:GetService("RunService")
local RS = game:GetService("ReplicatedStorage")
local last_time = os.clock()*1000
local list_len = 50
local ten_list = {}
local tmpl = 0
local function Beep(new,old)
if(#ten_list<list_len) then
table.insert(ten_list,new-old)
else
table.remove(ten_list,list_len)
table.insert(ten_list,new-old)
end
--print(#ten_list)
local max = 0
local maxi = 0
local second_max = 0
local tot = 0
for i,v in pairs(ten_list) do
if(v>max) then
second_max = max
max = v
maxi = i
elseif(v>second_max) then
second_max = v
end
tot+=v
end
if(tmpl>=list_len) then
task.spawn(function()
task.wait(math.random(.01,10.00))
print(ten_list)
print("^^^\tMax index: "..maxi.."\tMax & Second max: "..math.floor(max).." & "..math.floor(second_max))
end)
tmpl = 1
else
tmpl+=1
end
return
end
RUN.Heartbeat:Connect(function()
local now = os.clock()*1000
Beep(now,last_time)
last_time = now
end)
I’m seeking finding out why it spikes at 7 or 8 to then see if there’s any solutions to it.
I also have a place with unlocked copying ServerStatsTest UCL - Roblox
This is the output I had with the numbers in the script, changing list_len and no spawn and wait before printing hasn’t helped me any futher either…