1

I' am working on multiplayer game and server side is written with node.js with box2dweb. Server is on aws it's ubuntu 15 LTS (1GB RAM) virtual machine. Game is running fine when i start it within firs couple of hours, but after ~24h game is slowing down even thou no one have been playing during last 22h and last object was spawned 23 h ago. I've tried to use node.js profiler but i have very similar results when i start app and after one day of aplication working. What should i do? What is possible cause of my issue?

I've monitored time usage of functions among 10 min and here are the results :

gamelogic.update() ~40%

b2dWorld.update() ~47%

My profiller code:

var profiler = require('v8-profiler');
var fs = require('fs');
var startProfiling = function(duration){
    profiler.startProfiling('1', true);
    setTimeout(function(){
        var profile1 = profiler.stopProfiling('1');

        profile1.export(function(error, result) {
            fs.writeFile('./profile.cpuprofile', result);
            profile1.delete();
            console.log("Profile saved.");
        });
    },duration);
}
setTimeout(function(){
    startProfiling(1000 * 60 * 10);
},1000 * 60 * 60 * 24);

Should I stop listen to socket events on socekt before i delete socket ?

Top results in bash shell: - after 10 min of runnign 10% CPU usage and 8% RAM usage - after 4 days of running 80% CPU usage and 30% RAM usage

While measuring i have the same amount of game objects in the game + one player conected to server.

I have this message from node.js "(node:1324) Warning: Possible EventEmitter memory leak detected. 11 upgradeRequest listeners added. Use emitter.setMaxListeners() to increase limit" does garbage from this stay after deleting socket which called for too many same listener ?

peterSweter
  • 633
  • 6
  • 23
  • You said you looked at the profiler, what metrics you monitored ? CPU and RAM ? Because with the time the RAM usage can increase due a memory leak. Let us know what metrics you know are the same .. – Ido Oct 15 '16 at 19:16
  • I've only looked at percentage time usage of every function. – peterSweter Oct 15 '16 at 19:40
  • 1
    Start by looking at the output of `top` or `ps` both after 10 minutes and after 24 hours, and check both the process size and the CPU usage. Also, are there other things on the server that might have your node process swapped out? What does your node server do? Is it CPU-bound, I/O-bound? Does it use a database? – jcaron Oct 15 '16 at 19:56
  • 1
    use newrelic and it's package and monitor/profile Your stuff (; – num8er Oct 15 '16 at 20:09
  • @jcaron On this server is only my one game and one node.js process. I have Intel Xeon family processor with up to 3.3 GHz speed. I don't use any database. I had 3 days old process and i can see that wiht freesh proces after 10 min i use much less proc and 1/3 ram in comparsion to the long running process. – peterSweter Oct 15 '16 at 20:26
  • You probably have memory leaks, but there's no way for us to tell you where based on the code you've provided. – Paul Oct 15 '16 at 20:26
  • @Paul Is there some kind of valgrind for node.js ? Tha game is quite big so i can not post whole code there. I am asking for some tips that can lead me to solution of this problem. – peterSweter Oct 15 '16 at 20:37
  • There's a number of tools and techniques to choose from. A simple Google search yields https://www.alexkras.com/simple-guide-to-finding-a-javascript-memory-leak-in-node-js/ and https://www.toptal.com/nodejs/debugging-memory-leaks-node-js-applications – Paul Oct 15 '16 at 20:47
  • Possible duplicate of [NodeJS : How to debug "EventEmitter memory leak detected. 11 listeners added"](https://stackoverflow.com/questions/15581978/nodejs-how-to-debug-eventemitter-memory-leak-detected-11-listeners-added) – Paul Sweatte Aug 07 '17 at 19:03

0 Answers0