Author Topic: Running server-app.exe in background / mono-service uses 99% CPU  (Read 6906 times)

Monkey Man

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Hey there Aren,

I've been running tests with our game and we've been using mono command to start the "server.exe" app.  We just started using the command "mono-service2" to launch our server application to run the server in the background at a process instead; it's using 99% of the cpu =/ .  We figured it might be because the server is trying to Console.ReadLine() in the main thread but that didn't fix the issue.  The "server.exe" only uses .3 when "idling" (no clients are connecting) if launched with "mono".

Is there anything else that you know we should comment out to fix this issue?  If not, how would you go about launching the server application remotely (via ssh) using the "mono" command and having it as a background process? I tried "mono <server.exe> &" but that closes and exits the application as soon as I type another command that follows it.


EDIT:

After doing some debugging trying nohup and reading the output, i can see that this line continuously repeating.

Press 'q' followed by ENTER when you want to quit.



Thank you as always,

-Monkey Man
« Last Edit: October 11, 2013, 02:33:54 PM by Monkey Man »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Running server-app.exe in background / mono-service uses 99% CPU
« Reply #1 on: October 12, 2013, 09:08:59 AM »
The server app itself is running a loop where it prints that line, then waits for user input. If you're removing the user input, you should also remove this line -- and put a thread sleep command in there instead.

Monkey Man

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Running server-app.exe in background / mono-service uses 99% CPU
« Reply #2 on: October 12, 2013, 01:31:12 PM »
That did it!

I managed to figure out another alternative that works as well.

If you comment out the following lines and run this command nohup mono TNServer.exe > cent.out 2> cen.err < /dev/null & the server will idle without hogging the CPU and it will continue to run in the background. :)

But you'd have to right an alternative method to safely stop the GameServer and LobbyServer if you want to save data out to a .dat file.  I'm storing my data to a remote mysql and i wrote an argument that closes the threads and waits for all remaining writes to the db to finish before closing the server.


  1. //                      for (; ; )
  2. //                      {
  3. //                              Console.WriteLine("Press 'q' followed by ENTER when you want to quit.");
  4. //                              string command = Console.ReadLine();
  5. //                              if (command == "q") break;
  6.             //}
  7.             //console.writeline("shutting down...");
  8.  
  9.             //// close all opened ports
  10.             //if (up != null)
  11.             //{
  12.             //    up.close();
  13.             //    up.waitforthreads();
  14.             //    up = null;
  15.             //}
  16.  
  17.             //// stop the game server
  18.             //if (gameserver != null)
  19.             //{
  20.             //    gameserver.saveto("server.dat");
  21.             //    gameserver.stop();
  22.             //    gameserver = null;
  23.             //}
  24.  
  25.             //// stop the lobby server
  26.             //if (lobbyserver != null)
  27.             //{
  28.             //    lobbyserver.stop();
  29.             //    lobbyserver = null;
  30.             //}
  31.                 }
  32.                 Console.WriteLine("There server has shut down. Press ENTER to terminate the application.");
  33.         Console.WriteLine("But have we really?");
  34.                 Console.ReadLine();

TheCodeTraveller

  • Guest
Re: Running server-app.exe in background / mono-service uses 99% CPU
« Reply #3 on: October 30, 2013, 07:54:29 AM »
Hi there,

Note you're working with db, how are you running your queries as to not block the main packet handler? Just hitting those with new threads or is your database access fairly limited?

Regards,

EDIT: Forgot to mention that I've also seen the above behavior when running in mono debug session. Haven't been able to get connectivity working though, moved out the standalone ot a windows vm which of course makes debugging awesome *not*. There again, debugging the master server without timing out your clients isn't an easy feat either. Looking at the code journal playback system code won't be easy to integrate.