I have two options to run child process to send request to a HTTP server. One through a Node.js child process making a http request through built-in node support or through the 'request' module. Another option is to fork a C child process using libcurl api. The main http server is a Node.js server which will fork the child process. It can fork both a C executable or a Node.js executable.
Has anyone benchmarked or is aware of the performance issues involved in the two options. Both C and Node.js programming skills are available.
I would suggest a third option, use a libcurl binding for Node.js directly: https://github.com/JCMais/node-libcurl
const { curly } = require('node-libcurl');
const { statusCode, data, headers } = await curly.get('http://www.google.com')
or a more verbose way (without promises):
const { Curl } = require('node-libcurl');
const curl = new Curl();
curl.setOpt('URL', 'www.google.com');
curl.setOpt('FOLLOWLOCATION', true);
curl.on('end', function (statusCode, data, headers) {
console.info(statusCode);
console.info('---');
console.info(data.length);
console.info('---');
console.info(this.getInfo( 'TOTAL_TIME'));
this.close();
});
curl.on('error', curl.close.bind(curl));
curl.perform();
I've done some basic benchmarks and it seems to be the fastest URL client for Node.js (but benchmarks should always be taken with a grain of salt). It supports most libcurl options.
Disclaimer : I'm the author of the package
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.