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 
 
nwserver at 99% cpu when detaching from console

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux technical support
View previous topic :: View next topic  
Author Message
Mycohl



Joined: 21 Oct 2006
Posts: 8

PostPosted: Sat Mar 21, 2009 19:39    Post subject: nwserver at 99% cpu when detaching from console Reply with quote

No matter what I try to detach it, the nwserver process either hangs or goes up to 99% cpu usage. This has not happened to me before, although this is the first time I have tried to set up nwnx on an Ubuntu machine.

Right now, I've got a modified nwnstartup.sh script which I can either include the detach in, or just detach the script itself from the console. I've tried both, and they both seem to leave nwserver at 97-99% cpu.

My previous setup using a named pipe does not seem to work. Redirecting to /dev/null does not seem to work. I am at the limit of my limited shell knowledge at this point, and any help would be greatly appreciated. If you need additonal information, please let me know and I will post it.

Thank you for your time,
Myc
Back to top
View user's profile Send private message
Mycohl



Joined: 21 Oct 2006
Posts: 8

PostPosted: Sat Mar 21, 2009 20:05    Post subject: Reply with quote

For the record, I would also like to ask what the best way to currently run the thing without having an ssh window open is.

I seem to be stuck with one of two results: either I pipe the input and output and the nwserver goes up to 99%, or I don't, in which case it dies as soon as I detach it or close the ssh connection.

This is really NOT how it was working on Fedora, and I'm wondering if I am doing something wrong? Did something change?
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Sat Mar 21, 2009 21:22    Post subject: Reply with quote

Try screen? That will let you reattach and enter commands if necessary, too.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Mycohl



Joined: 21 Oct 2006
Posts: 8

PostPosted: Sat Mar 21, 2009 22:48    Post subject: Reply with quote

Thank you. Screen appears to be working fine with nwserver, although unfortunately I can't get start-stop-deamon to work with it. I'll play with it a bit more.

Thanks again for the info.
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Sun Mar 22, 2009 12:04    Post subject: Reply with quote

Screen is especially powerful when combined with Expect. You can use Expect for starting/stopping the server.
Back to top
View user's profile Send private message
metamud



Joined: 30 Sep 2008
Posts: 16

PostPosted: Sun Mar 22, 2009 16:59    Post subject: Reply with quote

Mycohl wrote:
For the record, I would also like to ask what the best way to currently run the thing without having an ssh window open is.

I seem to be stuck with one of two results: either I pipe the input and output and the nwserver goes up to 99%, or I don't, in which case it dies as soon as I detach it or close the ssh connection.

This is really NOT how it was working on Fedora, and I'm wondering if I am doing something wrong? Did something change?


The 99% CPU is caused by the server continually reading from stdin, which becomes an invalid filedescriptor as soon as you terminate your ssh session. The server select()'s on a number of filedescriptors (among which is stdin), the OS system call select() immediately "falls through" because one of its filedescriptors is invalid. Then nwserver tries to read from stdin, but there is nothing to be done (in fact, it gets E_BADF for even trying to read from an invalid filedescriptor) and the circle is complete as nwserver goes back to select() (only to immediately fall through again etc. etc.).

In short, what you are witnessing is nwserver doing thousands of futile attempts to read from stdin per second.

A shell-based approach

From reading "nwserver -help" I figured that the "-quiet" option will make "nwserver" properly detach std{in,out}:
Code:
# ./nwserver -help
[..]
-quiet
      Run without printing to stdout or reading from stdin, will run in background.

which makes it "ssh logout"-proof. In my case at least, I have no problems logging off. Heck it's even automated to startup if the power goes off and comes back on.


I have a crontab setup like this:
Code:
@reboot /usr/sbin/mysqld > ~/install/logs.0/mysqld.txt 2>&1 &
@reboot ~/install/server-loop.sh >/dev/null 2>&1 &

@daily pkill nwserver


"man crontab" (in lieu of manpages, google works fine) is your friend here.

Then I have a server-loop.sh script:
Code:
#! /bin/bash

BASE=/home/nwn/install
LOGDIR=${BASE}/logs.0
LOGFILE=${LOGDIR}/server_loop.txt

cd $BASE

while (true)
do
        echo "`date`: Rotating logfiles"
        savelog -c 3 -n -q $LOGDIR/*.txt

        echo "`date`: Starting server"
        ./nwnstartup.sh -quiet >>$LOGFILE 2>&1
done


Alert readers will note that as I have redirected stdout and stderr in my crontab, any output from the server-loop.sh script is ditched, when run from cron.

Finally, my version of the ubiquitous nwnstartup.sh script (please substitute your own password):
Code:
#! /bin/bash

export LD_PRELOAD=./nwnx2.so

./nwserver \
        -publicserver 1 \
        -servername MetaMud \
        -oneparty 0 \
        -pvp 1 \
        -difficulty 3 \
        -elc 1 \
        -ilr 0 \
        -reloadwhenempty 0 \
        -port 5121 \
        -maxclients 32 \
        -servervault 1 \
        -maxlevel 40 \
        -gametype 9 \
        -autosaveinterval 0 \
        -dmpassword SOME_SECRET \
        -module "MetaMud" \
        "$@"


This is all on an Ubuntu 8.04.2 "hardy" box (32-bit in case you think it is relevant).

The previously suggested "screen" solution works because it perpetuates the life of std{in,out,err} of nwserver for the duration of the "screen" session. The screen solution also allows you to enter console commands into the server at a later time (e.g., from another ssh session). I don't need to enter console commands, but if you do, my approach may be less feasible for you, as it does not readily offer an alternative way of sending input to nwserver's stdin (which has been closed already).

Hope this helps!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux technical support 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