Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to measure lag using a script and what is an alarming "amount of lag"?

Asked by 6 years ago

(This is about lag in terms of framedrops, scripts taking long to finish, glitchyness, general stuff that happens if you use too much calculation time, sorry if I didn't word the title correctly)

I have a game that uses a lot of intensive scripts, I can see script performance peak at some points. The script that uses the most calculation time is one that loads a graph in the beginning of the game and peaks at 55%. That's just loading in the beginning, while players have to wait anyway, so it's nothing too bad if that causes framedrops etc, it'll be over soon enough anyway. The problem is when the game actually starts, there are potentially hundreds of scripts running then to control my zombies(I made them a bit more intelligent than the standard zombie, but that took some sacrifices in performance).

Right now I see that the performance for 100 zombies stays at around 3%, but can peak to 5% if a lot of them need to do the heavy part of the calculations at the same time. (Also, if I have 100 of the same scripts running and it says 3%, is that for all 100 combined or for each one separatly? I know 300% is kinda impossible, but you never know lol)

I have one suggestion myself that could measure it, but I don't know how useful it might be. I read on the roblox blog that a wait() may change in length depending on how much calculation power you have. So knowing that I put up this simple bit of code:

while true do
    local waittime = wait()
    print(waittime)
end

Using this bit of code during that loading time that took 55% performance I did notice that it could go up to 0.09 while it's supposed to be 0.3333333. However, is this a general thing I can use? Can I just assume that the bigger that number is, the greater the lag, the more I should lower refreshrate in my calculations? And are there better alternatives?

2 answers

Log in to vote
0
Answered by 6 years ago

I Ain't No Scripting Specialist But You Can Measure The Activity By Going In Game (Not In Studio) Then When You Load In Press F9 To Open The Dev Console And Goto ServerScripts/ServerMemory. In ServerScripts Just Click On Which You Want To View The Activity Of

0
Yeah I know, but it's not just for having the information, I'd like to make something that can measure the lag and adapts the scripts accordingly. For exemple, if the script notices a lot of lag, it would increase waittimes for certain calculations, getting a bit of the load off of the server. HarrySnotte 7 — 6y
Ad
Log in to vote
0
Answered by
ozzyDrive 670 Moderation Voter
6 years ago

The frame rate is the only way to measure a machine's "lag". All machines are different; they got different hardware and settings -> different amounts of computing power. Thus when working with your game, you might want to have access to low-end hardware to test the compatibility.

For Roblox specific development, you want to understand the differences between the default wait function and the RunService's three events (RenderStepped, Stepped and Heartbeat).

Roblox's task scheduler calls every function connected to the RenderStepped event before a frame is drawn. You want to use this event for visual effects, not heavy calculations, otherwise you will see issues with the frame rate.

The Stepped and Heartbeat events -- among with other stuff such as resuming wait calls -- are fired after a frame is drawn. Heartbeat is the very last thing the scheduler goes through. The scheduler doesn't need to wait for these function calls to terminate, so you should be doing all the necessary calculations during these two events.

Here's a discussion on the devforums that explains this procedure.

The reason your wait call returns such a huge time delta is because of the frame rate. Threads yielding with the wait function are resumed after a certain amount of time has passed -- but the scheduler can only check the delta after a frame is drawn. An FPS of 1 would lead to the wait function yielding only a minimum of 1 second. Also the reason the script performance with that specific script peaks at 55% is because of the print call. It's a surprisingly expensive operation.

The script performance of 5% for the NPC scripts is the total and it's not too much. To actually optimize said code, it depends on what you already are doing and how. You don't need to do every calculation every tick. It is up to you to decide which calculations are the most important and need to be done the most frequently.

Another thing you might want to consider is, do you really need all the zombies in there at the same time? There's a reason you see NPCs spawning in even some triple-A games. The trick is to hide the spawning as well as possible.

Answer this question