Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Loading flags on login (https://forums.graalonline.com/forums/showthread.php?t=134260869)

Cubical 10-19-2010 04:59 AM

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?

fowlplay4 10-19-2010 05:28 AM

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.

salesman 10-19-2010 05:33 AM

I usually load data on login, and then maintain a cache (clientr.vars or something)

Cubical 10-19-2010 05:39 AM

Quote:

Originally Posted by fowlplay4 (Post 1607289)
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 (Post 1607290)
I usually load data on login, and then maintain a cache (clientr.vars or something)

that's what i'm currently doing

fowlplay4 10-19-2010 05:58 AM

Quote:

Originally Posted by Cubical (Post 1607291)
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.

xXziroXx 10-19-2010 11:26 AM

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.

xXziroXx 10-19-2010 08:15 PM

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.


All times are GMT +2. The time now is 06:43 PM.

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