LearnBoost / cluster

Node.JS multi-core server manager with plugins support.
http://learnboost.github.com/cluster
MIT License
2.29k stars 159 forks source link

Server does not respond #99

Closed djui closed 13 years ago

djui commented 13 years ago

I tried to port my express server to use cluster instead of spark2, but after starting it no response ever gets an answer (times out). I tried to follow https://github.com/LearnBoost/cluster/blob/master/examples/express.js but no change.

I have no idea how to show you some debug info besides the following:

» node server.js                  
  info - master started         
  info - worker 0 spawned         
  info - listening for connections
>

... and...

» node server.js status
  master 18666 alive   
  worker 0 18694 alive 
  worker 1 10917 dead  
  worker 2 10918 dead  
  worker 3 10919 dead  
  worker 4 10920 dead  
  worker 5 10921 dead  
  worker 6 10922 dead  
  worker 7 10923 dead  

  debug - exit         
>                      

The configuration is as follows:

cluster(server)                          
  .in('production')                      
    .use(cluster.logger('logs'))         
    .listen(80)                          
  .in('development')                     
    .set('workers', 1)                   
    .use(cluster.logger('logs', 'debug'))
    .use(cluster.debug())                
    .listen(8001)                        
  .in('all')                             
    .use(cluster.stats())                
    .use(cluster.pidfiles('pids'))       
    .use(cluster.cli())                  
    .use(cluster.repl(8002));            
tj commented 13 years ago

and it 100% works with just node? (no spark)

djui commented 13 years ago

Yes. When I do the following change, everything works (no sparks involved):

/*                                       
cluster(server)                          
  .in('development')                     
    .set('workers', 1)                   
    .use(cluster.logger('logs', 'debug'))
    .use(cluster.debug())                
    .listen(8001)                        
  .in('production')                      
    .use(cluster.logger('logs'))         
    .listen(80)                          
  .in('all')                             
    .use(cluster.stats())                
    .use(cluster.pidfiles('pids'))       
    .use(cluster.cli())                  
    .use(cluster.repl(8002));            
*/                                       
server.listen(8001);                     

» curl http://127.0.0.1:8001
<html></html>

If you want to have a look, the code I use is this: https://github.com/djui/kgist/tree/cluster

tj commented 13 years ago

one think you might want to try, since often requiring the server in the master file ends up creating a bunch of db connections etc that are not ideal, is using cluster('./myapp') etc, which expects you to export the server via module.exports. this was nothing in that file is executed in master, only in the workers

djui commented 13 years ago

Tried that before as recommended but didn't help. But found the cause: When using the REPL feature of cluster one must not use+start the Node REPL. removing the repl.start() fixed it. Is that worth mentioning in the readme? Or a bug?

tj commented 13 years ago

what happened? you had your own repl and cluster's repl?

djui commented 13 years ago

Yes, I just added the cluster example code by copy and paste not being aware of that I still had my own repl require line still in the source file, including a start() on it. That conflicts with cluster without an error.