logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Decreasing area AI priority

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Feb 15, 2015 13:51    Post subject: Decreasing area AI priority Reply with quote

So I have just moved my server to a new server infrastructure that offers burstable performance.
Eg: when my cpu usage is below 20-30% I gain credits, which can then be used when the cpu usage is above 20-30 to give full access to a 3ghz processor.

I am trying to fine tune my server to make full use of this, I've been using the nwnx profiler to try and identify causes of cpu cycle consumption but it's not really narrowing it down for me.

My symptoms are as follows

Before anyone logs in, CPU is quiet 10-15%
When someone logs in 20-30, occasional spikes to 50%
When logging out back to 10-15ish

If however a rift spawns in the server ( a rift is a semi random event that spawns monsters in areas) then even after the rift is gone, and the player leaves, the CPU persists at 30-35% which although isn't high, it's not low enough to gain CPU credits. This CPU level would drain all CPU credits in 8 hours etc.
(the idea is that idle server accrues CPU credits, then uses them when players are on for increased performance)

My theory is that once combat occurs in an area, that area gains a flag giving it higher priority for hb's etc
If this is the case, I'm just wondering if there is anyway to return CPU priorities back to starting levels)
Has anyone got any idea on how to fix my CPU issue here?
Profiler doesn't highlight any bad scripts
Everything that gets called looks genuine and the call count is usually higher than the Ms count- suggesting an efficient script
Eg 4000 calls equating to 100ms is good vs
100 calls equating to 4000ms
Back to top
View user's profile Send private message
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Mon Feb 16, 2015 3:03    Post subject: Reply with quote

Can't you just softlimit the process to 5% of wallclock time while no players are online? Should be enough to keep the hb scheduler happy, unless there is anything important going on while no one is there?
_________________
silm.pw, a player-driven Forgotten Realms NWN1 persistent world for tinkerers.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Feb 16, 2015 12:51    Post subject: Reply with quote

Im not sure how I would do that in windows.
Most OS's don't have the power to refuse CPU cycles to applications.
The applications themselves have to govern their cpu cycles.

What I have been doing so far is putting

Code:

if(GetFirstPC()==OBJECT_INVALID){return;}


into the tops of many of the scripts that run regularly


If you can suggest a way of restricting cpu cycles to nwserver - I'd be willing to hear it, as thats the end goal I have
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Feb 16, 2015 13:07    Post subject: Reply with quote

http://stackoverflow.com/questions/71257/suspend-process-in-c-sharp


It seems we are both right.

OS's don't generally allow you to limit CPU, infact- you cannot limit CPU.
CPU is just used when its needed.

What you can do however, is suspend threads or full processes at rapid intervals in order to slow a process down.

I am using such an application now - which is called BEX - Which can set an upper limit for your cpu usage per process.
I am going to study its source and try to port to C# and then make it adaptive so it adjusts for player count.
Back to top
View user's profile Send private message
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Mon Feb 16, 2015 13:47    Post subject: Reply with quote

Baaleos wrote:
http://stackoverflow.com/questions/71257/suspend-process-in-c-sharp


It seems we are both right.

OS's don't generally allow you to limit CPU, infact- you cannot limit CPU.
CPU is just used when its needed.

What you can do however, is suspend threads or full processes at rapid intervals in order to slow a process down.

I am using such an application now - which is called BEX - Which can set an upper limit for your cpu usage per process.
I am going to study its source and try to port to C# and then make it adaptive so it adjusts for player count.


That's exactly what I meant. Linux has cgroups noawadays, or the simple SIGSTOP SIGCONT trick (that you mentioned).

If there isn't anything important going on inside nwserver when no players are online, you might as well suspend the process until someone tries to log in. Is that even cheaper? :)
_________________
silm.pw, a player-driven Forgotten Realms NWN1 persistent world for tinkerers.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Feb 16, 2015 18:40    Post subject: Reply with quote

Try nwnx_optimizations
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Feb 18, 2015 2:03    Post subject: Reply with quote

is nwnx_optimizations around for windows?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Feb 18, 2015 2:04    Post subject: Reply with quote

elven wrote:
Baaleos wrote:
http://stackoverflow.com/questions/71257/suspend-process-in-c-sharp


It seems we are both right.

OS's don't generally allow you to limit CPU, infact- you cannot limit CPU.
CPU is just used when its needed.

What you can do however, is suspend threads or full processes at rapid intervals in order to slow a process down.

I am using such an application now - which is called BEX - Which can set an upper limit for your cpu usage per process.
I am going to study its source and try to port to C# and then make it adaptive so it adjusts for player count.


That's exactly what I meant. Linux has cgroups noawadays, or the simple SIGSTOP SIGCONT trick (that you mentioned).

If there isn't anything important going on inside nwserver when no players are online, you might as well suspend the process until someone tries to log in. Is that even cheaper? Smile


I'd say you cannot suspend it completely - otherwise a player cannot log in.
Need to keep some sort of process activity going to accept the connection, then after login, can release the kraken
Back to top
View user's profile Send private message
elven



Joined: 28 Jul 2006
Posts: 259
Location: Germany

PostPosted: Wed Feb 18, 2015 10:43    Post subject: Reply with quote

Baaleos wrote:
I'd say you cannot suspend it completely - otherwise a player cannot log in.
Need to keep some sort of process activity going to accept the connection, then after login, can release the kraken


Yeah I know. I was thinking about some kind of very simple udp proxy that just resumes the process when a packet arrives. Haven't ever tested that idea though since I'm not limited by CPU cycles.
_________________
silm.pw, a player-driven Forgotten Realms NWN1 persistent world for tinkerers.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Feb 19, 2015 15:15    Post subject: Reply with quote

Strangely enough - it looks like my server has suddenly become more efficient in regards to its heart beats etc

I was using that BES application to limit the CPU usage to 70 of normal, but even with it turned off now - it seems that I am getting passive / idle CPU Usage at around 6-9%

Normally after 2-3 hours, when the heartbeats and events start spawning on the server, the CPU would spike to 60-80% even without players online.

I guess the check I added in for
if(GetFirstPC() == OBJECT_INVALID){return;}

Is having a positive impact.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group