Raised This Month: $ Target: $400
 0% 

Server lagg when loading rank


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
andrzN
Senior Member
Join Date: Jan 2010
Location: Bodø / Norway
Old 10-24-2012 , 14:17   Server lagg when loading rank
Reply With Quote #1

Hey Everyone!

I've got a problem on my server, and the problem is that the server gets a small lagg spike that
everyone on the server feels when someone write "/rank" in chat.

I will post the code I use for my rank below, and I was wondering what I can change to make the lagg
dissepear when someone say /rank, and if it's not possible to do so, do you have any suggestions to what I can do instead to solve this problem?

Thanks!

PHP Code:
register_clcmd("say /rank""CmdHideRank"); 
PHP Code:
public CmdHideRank(id)
{
    
    if( 
g_bUsedRank[id] )
    {
        Print(
id"Do not use this command to often !");
    }
    
    
CmdRank(id);
    
g_bUsedRank[id] = true;
    return 
PLUGIN_HANDLED;

PHP Code:
public CmdRank(id)
{
    new Array:
aNames, Array:aAuths, Array:aXPs;
    new 
iTotal SortTopPlayers(aNamesaAuthsaXPs);
    
    new 
szAuth[35];
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    new 
szAuth2[35], i;
    for( 
0iTotali++ )
    {
        
ArrayGetString(aAuthsiszAuth2charsmax(szAuth2));
        
        if( 
equal(szAuthszAuth2) )
        {
            new 
szData[256], szXP[11];
            
nvault_get(g_iVaultszAuth2szDatacharsmax(szData));
            
parse(szDataszXPcharsmax(szXP));
            Print(
id"Your rank is^x01 %i^x03 of^x01 %i^x03 with^x04 %i points", (1), iTotalstr_to_num(szXP));
            break;
        }
    }
    
    
ArrayDestroy(aNames);
    
ArrayDestroy(aAuths);
    
ArrayDestroy(aXPs);

__________________
Owner of Gamepark.se - Scandinavian Community

#1 - HideNSeek [Easyblocks] IP: eb.gamepark.se
#2 - HideNSeek [Noblocks] IP: nb.gamepark.se
#3 - HideNSeek [HNS Training Blocks] IP: training.gamepark.se
andrzN is offline
Send a message via MSN to andrzN
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-24-2012 , 14:21   Re: Server lagg when loading rank
Reply With Quote #2

How many threads are you going to create for this ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
andrzN
Senior Member
Join Date: Jan 2010
Location: Bodø / Norway
Old 10-24-2012 , 14:22   Re: Server lagg when loading rank
Reply With Quote #3

Quote:
Originally Posted by ConnorMcLeod View Post
How many threads are you going to create for this ?
I made two, I first made one in the other section, but then I figured this might be the right section so I posted it here instead. And it wasn't possible to delete the other thread, so thats why
__________________
Owner of Gamepark.se - Scandinavian Community

#1 - HideNSeek [Easyblocks] IP: eb.gamepark.se
#2 - HideNSeek [Noblocks] IP: nb.gamepark.se
#3 - HideNSeek [HNS Training Blocks] IP: training.gamepark.se
andrzN is offline
Send a message via MSN to andrzN
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 10-24-2012 , 17:29   Re: Server lagg when loading rank
Reply With Quote #4

post SortTopPlayers

Last edited by jimaway; 10-24-2012 at 17:29.
jimaway is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 10-25-2012 , 08:15   Re: Server lagg when loading rank
Reply With Quote #5

There is probably a better way than using Dynamic Arrays and all of the natives required for that.
I see you use nvault as your data structure....SQL will also be faster because it has sorting functions built into it. simply "SELECT name, sid, xp FROM xp_table ORDER BY xp DESC;"

Then print your query to your html document.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-25-2012 , 09:25   Re: Server lagg when loading rank
Reply With Quote #6

Try to use MySQL.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
andrzN
Senior Member
Join Date: Jan 2010
Location: Bodø / Norway
Old 10-25-2012 , 09:34   Re: Server lagg when loading rank
Reply With Quote #7

Okey, I don't know how to change the saving / loading code, and I don't know how to make it save in mysql instead of nvault..
I'll upload the plugin here, and if theres any of you that have a little time to help me, I would really appreciate it a lot! Thanks!

I would rather like it to be in normal nvault instead of mysql, if thats possible
Attached Files
File Type: sma Get Plugin or Get Source (Pointmod_Needhelp.sma - 522 views - 34.8 KB)
__________________
Owner of Gamepark.se - Scandinavian Community

#1 - HideNSeek [Easyblocks] IP: eb.gamepark.se
#2 - HideNSeek [Noblocks] IP: nb.gamepark.se
#3 - HideNSeek [HNS Training Blocks] IP: training.gamepark.se

Last edited by andrzN; 10-25-2012 at 09:35.
andrzN is offline
Send a message via MSN to andrzN
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-25-2012 , 10:01   Re: Server lagg when loading rank
Reply With Quote #8

No wonder why it lags, you create 3 dynamic arrays each time and inserts probably a lot of entries + read nvault file at the same time. Inserting in a dynamic array is very slow. You should cache more datas, like pre-loading any necessary datas at map start from nvault file in some vars, dealing/updating datas with these vars, and saving in nvault file on change map or something.
__________________
Arkshine is offline
andrzN
Senior Member
Join Date: Jan 2010
Location: Bodø / Norway
Old 10-25-2012 , 10:30   Re: Server lagg when loading rank
Reply With Quote #9

Quote:
Originally Posted by Arkshine View Post
No wonder why it lags, you create 3 dynamic arrays each time and inserts probably a lot of entries + read nvault file at the same time. Inserting in a dynamic array is very slow. You should cache more datas, like pre-loading any necessary datas at map start from nvault file in some vars, dealing/updating datas with these vars, and saving in nvault file on change map or something.
I think I understand what you mean. But you should know I didn't code this plugin myself, I'm not nearly good enough to code.
I have no idea how to fix what you said was wrong, I am abseloutely blank on that area.

Do you think you could do it for me? If no, I still appreaciate your help, thanks!
__________________
Owner of Gamepark.se - Scandinavian Community

#1 - HideNSeek [Easyblocks] IP: eb.gamepark.se
#2 - HideNSeek [Noblocks] IP: nb.gamepark.se
#3 - HideNSeek [HNS Training Blocks] IP: training.gamepark.se

Last edited by andrzN; 10-25-2012 at 10:31.
andrzN is offline
Send a message via MSN to andrzN
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 10-25-2012 , 14:01   Re: Server lagg when loading rank
Reply With Quote #10

I think you have to post that at Requests category.
__________________

Last edited by claudiuhks; 10-25-2012 at 14:02.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
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 -4. The time now is 15:31.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode