Solved Massive lag spikes caused by time interval events

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Gladrian

Member
Feb 20, 2017
41
3
0
25
Skript version: bensku dev32

My server has been experiencing a big lag spike every 5 minutes for quite a while now. I've taken lots of timings reports, but they all give different reasons for the spikes. Here's what one looks like:
https://timings.spigotmc.org/?url=lanevopope

I've already checked through all of my 5 minute interval events and even turned them off for a while, but it didn't really seem to be what was executed within the intervals that affected it. If I turned off one set of intervals, another (ex: 1600 ticks aka 1 minute) would apparently be the cause. Is there something bugged with interval events that causes this?

Note: I do have ~4 or 5 five minute intervals going at once, but half intentionally only do something every hour. The rest don't do anything so intensive as to cause a spike.

At a loss as to what it could be after I've "fixed the lag spikes" several times by now.

Thanks
 
I wouldn't use periodical events if I were you, they're known to be really laggy and might be one of the causes why it's lagging your server. For me, a while loop when Skript is loaded is the best thing to do. Here an example:
code_language.skript:
on skript load:

  set {scheduler::1} to 5 minutes
  while {scheduler::1} is set:
    #do stuff
    wait {scheduler::1}
And if you have MundoSK, I'd put that into a sync scope, just to override some weird behaviours.
 
  • Like
Reactions: Gladrian
I wouldn't use periodical events if I were you, they're known to be really laggy and might be one of the causes why it's lagging your server. For me, a while loop when Skript is loaded is the best thing to do. Here an example:
code_language.skript:
on skript load:

  set {scheduler::1} to 5 minutes
  while {scheduler::1} is set:
    #do stuff
    wait {scheduler::1}
And if you have MundoSK, I'd put that into a sync scope, just to override some weird behaviours.

Awesome, thank you! Will update on if that fixes it.
 
Awesome, thank you! Will update on if that fixes it.
Note that while loop won't stop when the script is reloaded. You can use a system like this to fix that:
code_language.skript:
on script unload:
  delete {while::*}
function startWhile(n: text) :: text:
  set {_s} to new uuid
  delete {while::%{_n}%::*}
  set {while::%{_n}%::%{_s}%} to true
  return {_s}
function running(i: text, s: text) :: boolean:
  return not ({while::%{_s}%::%{_i}%} == null)
on script load:
  set {_wait} to 5 minutes
  set {_id} to startWhile(script)
  while running({_id}, script):
   #code
    wait {_wait}
 
  • Like
Reactions: Gladrian
I've converted all my periodicals into that format and they work well, but the crashes didn't go away. I actually cleared all the scheduler variables so that'd all scheduled events would cease, but the spikes still happened regardless. I have found this error in my console though:

09.11 12:34:06 [Server] ERROR Skript cannot save any variables to the database 'default'. The server will hang and may crash if no more variables can be saved. 09.11 12:34:06 [Server] WARN Cannot write variables to the database 'default' at sufficient speed; server performance may suffer and many variables will be lost if the server crashes. (this warning will be repeated at most once every 10 seconds)

Perhaps this is the cause of the spikes. What kind of thing would create this error? And how is it fixed?

Thanks for all the help already!
 
if we learn 3rd grade reading
it says Cannot write variables to the database 'default' at sufficient speed
now using some reading comprehension we can figure out that your saving to many variables to quickly
 
if we learn 3rd grade reading
it says Cannot write variables to the database 'default' at sufficient speed
now using some reading comprehension we can figure out that your saving to many variables to quickly

My intent in that question was to ask what causes the nature of that error, not literally what it means. I haven't seen it pop up for a while, so I assume it was caused by lag not allowing efficient variable writing as opposed to one one my scripts constantly calling for massive amounts of variables to be saved.
[doublepost=1510374566,1510289258][/doublepost]Okay, so I have all scripts and plugins disabled besides Skript and this script:

code_language.skript:
every 10 ticks:
    if {last.check} is set:
        set {_elapsed} to difference between now and {last.check}
        if {_elapsed} is greater than 3 seconds:
            if {_elapsed} is less than 6 seconds:
                broadcast "&o&7Small spike of %{_elapsed}% detected..."
            else:
                broadcast "&o&l&4Lag spike detected: &f%{_elapsed}%"
                if {last.spike} is set:
                    broadcast "&cPeriod since last spike: %difference between now and {last.spike}%"
                add 1 to {spike.count}
                set {last.spike} to now
    set {last.check} to now

Despite that, the spikes still occur every 10 minutes according to the spike announcer. In fact, the "every 10 ticks" loop seems to be the exact cause. For example, if I change the interval to 20 ticks, a spike occurs every 20 minutes, and if I change it back to 10 ticks, a spike occurs every 10 minutes once again. Unfortunately, @Snow-Pyon's alternative doesn't seem to fix it. What's the cause of all of this even though I have everything else disabled?

EDIT: I should also mention that changing the interval to every 5 minutes or something and having a loop within that artificially creates a 10 tick periodical didn't fix it. It seems like any periodical can cause this, and the spike interval is always something 20 minutes or less.






[doublepost=1510521404][/doublepost]I found the issue! I've been working with Skript for 3+ years, and I haven't once reset my variables.csv file. I was less conservative of data storage in the past, so I had about 800 thousand variables being stored. Although the odd thing is, there was a time when I had 1.2 million before I cleared a bunch of them after a server reset, and I wasn't getting spikes then.

For whatever reason Skript had had it with the variables this time around and was spiking whenever the variables needed to be saved, which was quite often within the periodicals I had going. To fix it, I did the forbidden and manually removed about 600k variables from variables.csv in Excel. I did lose some undeleted vars in the reload, but most things are intact, and the spikes are finally gone.

Thanks to all the productive replies, and sorry for my cluelessness! I'll have to watch out for this issue in the future.

P.S. -- Marking Snow-Pyon's response as the best answer since it's a really good alternative to periodicals. Pikachu's addition to it is also really helpful :emoji_slight_smile:
 
  • Like
Reactions: Snow-Pyon
Status
Not open for further replies.