Role
Data\LuaAPI\LuaAPI.ini holds the limits that GameServer uses to protect itself from slow or faulty scripts. A script that loops forever, uses too much memory or sends too many packets is stopped on its own; GameServer and the other scripts keep running.
- The file is read every time LuaAPI / Lua UI is loaded (GameServer startup or pressing Reload LuaAPI); GameServer does not need to be restarted.
- If the file or a key is missing, the default value is used. A value outside the allowed range is automatically clamped to the nearest limit.
- When loading, the log writes a line
[LuaAPI] settings: Timeout ... ms, MemoryLimit ... MB ...so you can check the values in use.
The default values have been tested with thousands of players online. Change them only when you know exactly why (for example a module needs to run longer when loading a large amount of data).
Section [LuaAPI]
| Key | Default | Allowed | Meaning |
|---|---|---|---|
Timeout | 2000 | 100 - 60000 | The maximum number of milliseconds a script function may run each time GameServer calls it (event, command, timer). If exceeded the function is stopped and the log writes script ran longer than ... ms; the next function of the same event is timed again from the start. |
LoadTimeout | 10000 | 1000 - 120000 | The maximum time when running Main.lua, WebAPI.lua and onGameServerStart (loading large configuration tables takes longer). |
TimeoutResets | 3 | 0 - 20 | Within one GameServer call, how many functions may be stopped for running too long before the whole call is stopped. |
EventBudget | 50 | 5 - 1000 | The number of milliseconds each server loop spends on queued events (entering the game, monster death, receiving items...). The remainder waits for the next loop, so many simultaneous events do not make the server stall. |
MemoryLimitMB | 256 | 32 - 4096 | The maximum memory of all LuaAPI scripts. A script that asks for more when the limit is reached gets the error not enough memory (only that function is stopped). |
HookCount | 100000 | 1000 - 10000000 | Time and memory are checked once every this many Lua instructions. Smaller: it stops faster but scripts run slightly slower. |
MaxQueue | 20000 | 1000 - 1000000 | The maximum number of queued events waiting to be sent to scripts. Beyond this they are dropped and logged. |
MaxRows | 10000 | 100 - 1000000 | The maximum number of rows DB.Query returns to a script. Extra rows are dropped (logged): use TOP / WHERE in the query. |
CommandRate | 5 | 1 - 100 | The number of Lua chat commands (Data\Commands\LuaCommands.xml) a player may use per second. Faster commands are ignored (blocks bots / modified clients that send commands in bursts). |
SendRate | 30 | 5 - 1000 | The number of packet "units" a script may send to one player per second. A normal packet = 1, Player.ReCalc / Player.SendLevels = 3, Player.SendInfo = 5, Inventory.SendList / Object.ViewportCreate = 10. If exceeded the call is ignored (logged once). A client that receives hundreds of packets at once will crash; this limit protects players. |
BroadcastRate | 20 | 1 - 1000 | The number of server-wide notices per second (Message.SendAll, SendGlobal, BoxAll, Post, Map.Fireworks). If exceeded they are ignored. |
SlowCallWarning | 50 | 0 - 60000 | An event or module function that runs longer than this number of milliseconds is logged as slow (at most once per minute per name), helping you find the module that slows the server. It is only a warning; the function is not stopped. 0 = off. |
Section [LuaUi]
| Key | Default | Allowed | Meaning |
|---|---|---|---|
Timeout | 5000 | 100 - 60000 | The maximum time a Lua UI function may run (button press, window message). |
MemoryLimitMB | 128 | 16 - 4096 | The maximum memory of all Lua UI scripts. |
Example
[LuaAPI]
; A module loads a very large configuration file at startup: allow 20 seconds
LoadTimeout = 20000
; Log every function that runs longer than 20 ms to find slow modules
SlowCallWarning = 20
Save the file, then press Reload LuaAPI in START. Look for the line [LuaAPI] settings: ... in the GameServer log to make sure the new values are in use.
Reading slow warnings
| Log line | Meaning |
|---|---|
[LuaAPI] slow script: onPlayerLogin took 120 ms | The whole onPlayerLogin event (every module attached to it) took 120 ms. |
[onPlayerLogin] MyModule_OnLogin: slow (95 ms, ...) | The function MyModule_OnLogin alone is slow: this is the module that needs optimizing. |
[onTimerProcessSecond] MyModule_Tick: stopped 3 times in a row ... switched off | The function was stopped for exceeding time / memory 3 times in a row, so it switched itself off until LuaAPI is reloaded. Fix the module and reload. |
See also: Error handling and safety notes.