Live data from Hacker News

Benchmarking Codswallop: Node.js vs. PHP

philsturgeon.co.uk

11–20 of 85 posts

Re: Benchmarking Codswallop: Node.js vs. PHP

#11

Node.js for web scraping usually is the obvious choice: Scraping using jQuery syntax such as: $('table tr').each(function(ix, el) { names .push($(el).find('td').eq(0)); surnames.push($(el).find('td').eq(1)); }) is more familiar to most web developers as opposed to the PHP syntax. Even if Node was 5x slower than PHP I would still go for Node because of its easy jQuery syntax.

> Even if Node was 5x slower than PHP I would still go for Node because of its easy jQuery syntax

That "jQuery syntax" has nothing to do with the language itself. jQuery uses Sizzle[0], which is a CSS selector library for JavaScript. There are plenty of PHP libraries which provide CSS selectors, such as the Symfony CssSelector component[1].

[0] https://github.com/jquery/sizzle

[1] https://github.com/symfony/CssSelector

Re: Benchmarking Codswallop: Node.js vs. PHP

#12
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

It think the problem is you are feeding into the same loop. There are also probably ways of making the PHP script go faster still.

Also, that seems like a bit of a magic flag to add / tune, why is that not the default, and would I have to keep tuning it for each of my apps?

Re: Benchmarking Codswallop: Node.js vs. PHP

#13
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

I didn't know about this maxSockets limitation.

Is this something safe to raise?

Re: Benchmarking Codswallop: Node.js vs. PHP

#14
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

This is the "insane default" that substack goes on a rant about in the hyperquest README: https://github.com/substack/hyperquest#rant

  There is a default connection pool of 5 requests. 
  If you have 5 or more extant http requests, any 
  additional requests will HANG for NO GOOD REASON.
This one trips up people on #node.js constantly and hopefully will be removed very soon.

Re: Benchmarking Codswallop: Node.js vs. PHP

#15
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

I didn't know about this maxSockets limitation. Is this something safe to raise?

http://nodejs.org/docs/latest/api/http.html#http_agent_maxso...

If you use it smart its safe enought

Re: Benchmarking Codswallop: Node.js vs. PHP

#16
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

I didn't know about this maxSockets limitation. Is this something safe to raise?

Default is 5. Should be just fine if you don't have a specific use case that would require higher limits.

If so, just crank it up, should be safe unless you assign Infinity or something like that and push it too much (then you have another problem though). We use 15 in production where our server parses a lot of external web pages.

Re: Benchmarking Codswallop: Node.js vs. PHP

#17
post #5

Node benchmark is flawed though. Add something like require('http').globalAgent.maxSockets = 64; at the top of node script if you want a fair comparison with async php version. The bottleneck is bandwidth here. Not the runtime. On my laptop, original script from the author took 35 seconds to complete. With maxAgents = 64, it took 10 seconds. Edit: And who is downvoting this? I just provided actual numbers and a way t…

I didn't know about this maxSockets limitation. Is this something safe to raise?

It's pretty much always safe to set to Infinity or to turn the agent off. This is an anti-feature.

Re: Benchmarking Codswallop: Node.js vs. PHP

#19
Long term php guy (I maintained APC for years, slowly given up now), so I've worked a lot with ~2k/3k request-per-second PHP websites.

The real trick here is async processing. A lot of the slow bits of PHP code is people not writing async data patterns.

If you use synchronous calls in PHP - mc::get or mysql or curl calls, then PHP absolutely sucks in performance.

Nodejs automatically trains you around this with a massive use of callbacks for everything. That is the canonical way to do things - while in PHP blocking single-threaded calls is what everyone uses.

The most satifying way to actually get PHP to perform well is to use async PHP with a Future result implementation. To be able to do a get() on a future result was the only sane way to mix async data flows with PHP.

For instance, I had a curl implementation which fetched multiple http requests in parallel and essentially lets the UI wait for each webservices call at the html block where it was needed.

https://github.com/zynga/zperfmon/blob/master/server/web_ui/...

There was a similar Memcache async implementation, particularly for the cache writebacks (memcache NOREPLY). Memcache multi-get calls to batch together key fetches and so on.

The real issue is that this is engineering work on top of the language instead of being built into the "one true way".

So often, I would have to dig in and rewrite massive chunks of PHP code to hide latencies and get near the absolute packet limits of the machines - getting closer to the ~3500 to 4000 requests per-second on a 16 core machine (sigh, all of that might be dead & bit-rotting now).

Re: Benchmarking Codswallop: Node.js vs. PHP

#20
post #9

Node.js for web scraping usually is the obvious choice: Scraping using jQuery syntax such as: $('table tr').each(function(ix, el) { names .push($(el).find('td').eq(0)); surnames.push($(el).find('td').eq(1)); }) is more familiar to most web developers as opposed to the PHP syntax. Even if Node was 5x slower than PHP I would still go for Node because of its easy jQuery syntax.

Did you bother to read the post? It pitted two different DOM traversal libraries against each other: * cheerio ( https://github.com/MatthewMueller/cheerio ) * PhpQuery ( https://code.google.com/p/phpquery/wiki/jQueryPortingState ) Both of these use a jQuery-esque syntax, so your comment regarding DOM traversal in PHP is a moot point.

Yeah the CSS style selectors and methods are the same, I assumed he was referring to the fact that it's all JS.

When you are scraping it's great to be able to do a test run in the browser console and then just paste the code into your node script without any language porting.

It's not an argument that it's better or faster or anything than PHP, just that some find it easier to hack a scraper together in this way.

Post reply on HN