Created
November 24, 2010 06:14
-
-
Save itissid/713195 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(doc=0 ; doc<this.docs.length; doc++ ){ | |
var self = this; | |
//Need to scale as too many connections are formed too quickly.. Server will drown...\ | |
//Suggested: process all the data through a Queue and an interval... | |
//The counter implementation is flaky... | |
(function testServer(data, docnum){ | |
if(self.openConn < 300){ | |
var s = new net.Stream(); | |
s.setEncoding('utf8'); | |
s.on('connect', function(){ | |
console.log('***Sending data for document:'+docnum); | |
console.log(data.length); | |
s.write(data+'\n', encoding='utf8'); | |
}) | |
//handler to recieve the data back after the inference. /Recieve the inference results. | |
s.on('data', function(data){ | |
console.log('*******DATA RECIEVED FOR:'+docnum); | |
console.log(data); | |
//s.end(); | |
self.procesedDocs++; | |
console.log('***Processed doc count:: '+self.procesedDocs); | |
//s.end(); | |
}) | |
s.on('close', function(had_error){ | |
//Should mean connection is closed by the server. | |
console.log('***Closed the doc ID connection'+docnum); | |
console.log('***Processed doc count:: '+self.procesedDocs);//these many docs recieved atleast | |
self.openConn--; | |
if(self.openConn <300 && self.processingQueue.length>0){ | |
//pop a connection and | |
var arr_t = self.processingQueue.pop(); | |
console.log('Processing queue doc ID:: ',arr_t[1]); | |
console.log('#open connections:'+self.openConn); | |
testServer(arr_t[0], arr_t[1]); | |
} | |
}) | |
s.on('end', function(){ | |
console.log('***CONNECTION ENDED FIN RECIEVED***'); | |
s.end(); | |
//Recieved when i hit ctrl^c or close the server my self... | |
}) | |
self.openConn++; | |
s.connect(socketPath); | |
}else{ | |
console.log('Pushing docnum: '+docnum+' to queue') | |
self.processingQueue.push([ data,docnum]); | |
} | |
})(this.docs[doc], doc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment