Skip to content

Pipe/stream performance regression after v2.5.0 #3477

@mhart

Description

@mhart

(extracting from #3429)

Not sure if this is something that's well known and/or being worked on, but just in case it's not flagged somewhere: certain streams (pipes?) still appear (as of v4.2.1) to be at only 70% of the performance they were in v2.5.0 and prior.

Here's how the performance looks for different node.js versions reading from the stdout of a spawned cat process on a 2GB file (the results are similar for reading from stdin):

linuxspawn

Generated using bench.sh (after npm install -g nave):

#!/bin/bash

VERSIONS="4.2.1 0.12.7 0.10.40 2.5.0 3.0.0 3.1.0"

fallocate -l 2000000000 file.dat

for i in 0 1 2 3 4 5; do
  for v in $VERSIONS; do
    nave use $v node spawn.js
  done
done

spawn.js:

var spawn = require('child_process').spawn

var FILE = process.argv[2] || 'file.dat'
var SIZE_MB = 2000

spawnPipe(function(err, time) {
  if (err) return console.error(err.stack || err)
  console.log([process.version, time].join(','))
})

function spawnPipe(cb) {
  var bytesRead = 0
  var time = process.hrtime()
  var cat = spawn('cat', [FILE], {stdio: ['ignore', 'pipe', 'ignore']})

  cat.stdout.on('data', function(data) {
    bytesRead += data.length
  })
  cat.on('error', cb)
  cat.on('close', function(code) {
    if (code !== 0) return cb(new Error('cat exited with: ' + code))
    if (bytesRead != SIZE_MB * 1000 * 1000) return cb(new Error('Incorrect bytes read: ' + bytesRead))
    var diff = process.hrtime(time)
    cb(null, SIZE_MB / (diff[0] + diff[1] / 1e9))
  })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    benchmarkIssues and PRs related to the benchmark subsystem.bufferIssues and PRs related to the buffer subsystem.streamIssues and PRs related to the stream subsystem.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions