2012-12-14 8 views
6

Stavo curiosando per esplorare recenlty nodejs e phantomjs e ho scritto un piccolo codice per misurare il tempo di caricamento della pagina. Ho trovato che i tempi di caricamento della pagina differiscono tra il codice phantomjs racchiuso in nodejs rispetto al puro codice phantomjs. Di seguito è riportato il codice: phantomjs e nodejs per il confronto:Nodejs + phantomjs vs pure phantomjs - tempo di caricamento della pagina

Nodejs:

var http = require('http'), 
phantom = require('phantom'); 
url = require("url"); 

http.createServer(function (request, response) { 
    var start = Date.now(); 

    request.on('end', function() { 
    phantom.create(function(ph) { 
     ph.createPage(function(page) { 
     var _get = url.parse(request.url, true).query; 

     page.open(_get[url], function(status) { 
      if (status == 'success') { 
      var time = Date.now() - start; 
      console.log(time); 
      } 
     }); 
     }); 
    }); 
    }); 
}).listen(80,''); 

Phantomjs:

var page = require('webpage').create(); 
var system = require('system'); 

var address = system.args[1]; 
var time = 0; 
var start = Date.now(); 

page.open(address, function (status) { 
    time = Date.now() - start; 
    console.log(time + ''); 
}); 

il tempo è di solito 4 volte di più quando si verifica un sito tramite phantomjs. Qualche idea?

+1

Scaricare il traffico di rete da PhantomJS (per entrambi i casi) e confrontarli. Vedi https://github.com/ariya/phantomjs/wiki/Network-Monitoring. –

+1

Si prega di chiarire, la chiamata phantomjs diretta è 4 volte più lunga di phantomjs e nodejs? –

+0

http://phantomjs.org/network-monitoring.html (Nuovo collegamento) –

risposta

0

PhantomJS non supporta i dati in uscita, apre solo pagine Web. phantomjs-node collegarli nel seguente modo: crea un'istanza di ExpressJS e trasmette i dati tramite il suo socket.io plus utilizzando altre due librerie. E i dati va:

pagina web> Phantom.js>dnode + node-browserify> Express.js>> Socket.io Node.js

Ho lo stesso problema con la velocità e le prestazioni ora leggere su node-webkit, ovvero WebKit nativo senza stampelle che supporta i moduli Node.js.