Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-19-2010, 04:59 AM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Loading flags on login

What's the best way to load commonly used variables from files? upon login or just when they are needed? I currently have like 50 variables loaded from files whenever a player logs on because I assumed it's better to just load everything at once but on the other hand could it cause server lag if say 10 players logged on simultaneously?
Reply With Quote
  #2  
Old 10-19-2010, 05:28 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Well account data is a flat file, and the server seems to handle that just fine every time a player logs on.

Idea: Stress-test your login..

PHP Code:
function onCreated() {
  
temp.start = timevar2;
  for (
temp.i = 0; temp.i < 100; temp.i++) {
    
loginTest();
  }
  echo(
"Took" SPC (timevar2 - temp.start) SPC "seconds!");
} 
If you aren't satisfied, you could 'load' it from an SQLite DB every time they log on but then you have to re-design your systems to constantly update the DB.
__________________
Quote:
Reply With Quote
  #3  
Old 10-19-2010, 05:33 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
I usually load data on login, and then maintain a cache (clientr.vars or something)
__________________
Reply With Quote
  #4  
Old 10-19-2010, 05:39 AM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Quote:
Originally Posted by fowlplay4 View Post
Well account data is a flat file, and the server seems to handle that just fine every time a player logs on.

Idea: Stress-test your login..

PHP Code:
function onCreated() {
  
temp.start = timevar2;
  for (
temp.i = 0; temp.i < 100; temp.i++) {
    
loginTest();
  }
  echo(
"Took" SPC (timevar2 - temp.start) SPC "seconds!");
} 
If you aren't satisfied, you could 'load' it from an SQLite DB every time they log on but then you have to re-design your systems to constantly update the DB.
Thanks I'll defiantly try that. What would you say is a good load time to have everything loaded?
Quote:
Originally Posted by salesman View Post
I usually load data on login, and then maintain a cache (clientr.vars or something)
that's what i'm currently doing
Reply With Quote
  #5  
Old 10-19-2010, 05:58 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Cubical View Post
Thanks I'll defiantly try that. What would you say is a good load time to have everything loaded?
It really depends on the complexity of the data and so on. If it takes less than 0.1 seconds for one person at login it's pretty safe to say you have nothing to worry about.

One of the things I recommend though is the use of getfilemodtime(file), and using it with your cache to determine if you have to load the file or not.

Once upon a time Zodiac loaded a text file for every item the player had, every time they logged on. Using getfilemodtime(file) I was able to decrease login loading time (after the initial load) dramatically.

A test..

PHP Code:
function onCreated() {
  
temp.start = timevar2;
  
temp.count = 0;
  for (
temp.a: allplayers) {
    
temp.prefix = temp.a.account.substring(0, 2);
    
temp.lines.loadlines(format("accounts/%s/%s.txt", temp.prefix, temp.a.account));
    
temp.file++;
    for (
temp.i = 0; temp.i < temp.lines.size(); temp.i++) {
      
temp.count++;
    }
  }
  echo(
"time" SPC timevar2-temp.start SPC "files parsed" SPC temp.file SPC "lines parsed" SPC temp.count);
} 
Output:

PHP Code:
The script of NPC JerretNPC has been updated by fowlplay4
time 0.266197919 files parsed 43 lines parsed 23422
The script of NPC JerretNPC has been updated by fowlplay4
time 0.042979001 files parsed 42 lines parsed 24392
The script of NPC JerretNPC has been updated by fowlplay4
time 0.040443897 files parsed 42 lines parsed 24390 
Seems fast enough to me.
__________________
Quote:

Last edited by fowlplay4; 10-19-2010 at 06:22 AM..
Reply With Quote
  #6  
Old 10-19-2010, 11:26 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
I've always found saving data to files to be more hassle than it's worth it, and a definite speed decrease comparing to SQLite tables. The way I handle items, skills etc. on Maloria is that I load everything once upon login to a player.items TStaticVar, and whenever an item is obtained during gameplay it's added both to that TStaticVar and saved into the SQLite table.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 10-19-2010, 08:15 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Speed check:


PHP Code:
Starting 'loadPlayerData()'...
Loaded 5 skills!
Loaded 0 spells!
Loaded 32 items!
Done! Function executed in 0.020627975 seconds!
Starting 'loadPlayerData()'...
Loaded 5 skills!
Loaded 0 spells!
Loaded 32 items!
Done! Function executed in 0.019389867 seconds!
Starting 'loadPlayerData()'...
Loaded 5 skills!
Loaded 0 spells!
Loaded 32 items!
Done! Function executed in 0.018626928 seconds! 
With less items:

PHP Code:
Starting 'loadPlayerData()'...
Loaded 5 skills!
Loaded 0 spells!
Loaded 7 items!
Done! Function executed in 0.005586862 seconds! 
Stress test for entire login process:

PHP Code:
100 players logging on at the same time took 1.678742885 seconds!
500 players logging on at the same time took 24.404337167 seconds! 
500 players (or even 100) logging on at the exact same time is very unlikely though.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.