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

Lua Performance on lua script, using database query

Stellow

C++/C#/PHP/LUA
Joined
Oct 23, 2008
Messages
1,106
Reaction score
214
Location
Germany
GitHub
eubrunomiguel
I have implemented a system on my server which on every experience stage update (character level up, event up/down) server query to retrieve a database value, which will be used to determine the next step on the script. Do you think would be more interesting creating a global variable, or this wouldn't hurt server performance?

Obs. Linux based, and database is local.

One reason I also ask this question, is because sometimes I check internal connections (for ddos purpose) and I see over 60 connections from 127.0.0.1, which I cannot track where they are coming from, if it is a script, website or something else, any ideas on this subject? If it affect anything or not?
 
I forgot how it's called, when you set a value to a valuable, you lock it to retrieve it's result without querying again, and only when you use a function to query, you unlock it to gather the new data, and then close it to fast access. I know it's work good on c++ and multiple threads, but I don't have much experience on that, specially on Lua, i don't know if could be implemented.
 
I have implemented a system on my server which on every experience stage update (character level up, event up/down) server query to retrieve a database value, which will be used to determine the next step on the script. Do you think would be more interesting creating a global variable, or this wouldn't hurt server performance?

Obs. Linux based, and database is local.

One reason I also ask this question, is because sometimes I check internal connections (for ddos purpose) and I see over 60 connections from 127.0.0.1, which I cannot track where they are coming from, if it is a script, website or something else, any ideas on this subject? If it affect anything or not?

I forgot how it's called, when you set a value to a valuable, you lock it to retrieve it's result without querying again, and only when you use a function to query, you unlock it to gather the new data, and then close it to fast access. I know it's work good on c++ and multiple threads, but I don't have much experience on that, specially on Lua, i don't know if could be implemented.

Making a variable global won't hurt the performance as it is just added to the _G table, all functions, metatables and their metamethods etc.. are loaded at startup and then referenced as needed, I highly doubt adding 1 more value regardless what it is will do any harm :p

A global variable in lua is declared without using the local keyword, not much more to it then that, you will want to make it accessible globally tho, so stick it in global.lua.

Initially you can set it to nil and then check if the value is not nil and if it is retrieve the data
Code:
-- set somewhere in global.lua
myGlobalVariable = nil

-- your script
if not myGlobalVariable then
-- assignment code
end

Almost every function in the tfs framework makes calls to the database so no need to worry about that as it is just 1 more call.

Unfortunately there is no simple way to lock a variable in lua like in c++ where you can declare a variable as a const since lua is a loosely typed language.

The only way to emulate this is to use conditions and it is not a 100% guarantee :p
 
Last edited:
Isn't a problem to change this variable value in game? Because I know for some function to work in-game they need to be reloaded.
Depends on where you are calling the data from, like in a spell script the data has to be loaded before it can be used, however even that data can be manipulated or altered.

If your looking for a definitive answer than you will not get one as you have not explained exactly what you are trying to accomplish (or rather provided any code), being vague about a problem you are having only leads to vague answers :p
 
I have implemented a system on my server which on every experience stage update (character level up, event up/down) server query to retrieve a database value, which will be used to determine the next step on the script. Do you think would be more interesting creating a global variable, or this wouldn't hurt server performance?

Obs. Linux based, and database is local.

One reason I also ask this question, is because sometimes I check internal connections (for ddos purpose) and I see over 60 connections from 127.0.0.1, which I cannot track where they are coming from, if it is a script, website or something else, any ideas on this subject? If it affect anything or not?
Instead of putting those values in the database you could just put them inside some table in the lib and then get the values from the table.

If you still wanna use database for some reason you could do an onStartUp event to load all values from the db and put them in a table to be read by the script.
 
Instead of putting those values in the database you could just put them inside some table in the lib and then get the values from the table.

If you still wanna use database for some reason you could do an onStartUp event to load all values from the db and put them in a table to be read by the script.
We already established this.. you must have missed the memo.
 
Instead of putting those values in the database you could just put them inside some table in the lib and then get the values from the table.

If you still wanna use database for some reason you could do an onStartUp event to load all values from the db and put them in a table to be read by the script.
ok but if you need to be updating values in the database all the time, on a server with more than 200 players, an example is if you need to make a pet system where each pet had the same values as one player,id, Health, exp, level, name, mana and you can trade anytime.
 
ok but if you need to be updating values in the database all the time, on a server with more than 200 players, an example is if you need to make a pet system where each pet had the same values as one player,id, Health, exp, level, name, mana and you can trade anytime.
Store them in a table and save them on server save or a globalevent to do that
 
I can make global tables?(how)
Just make a file.lua on data directory, and other scripts can access it. Depending on the Distro you are using, you may going to have to load this file on the init script. Otherwise, just make a table on a existing file, such as functions.lua, and it should work just fine.
 
Back
Top