-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance of ss.createBlobReadStream(blob).pipe(stream) #20
Comments
Thank you for reporting it. I want to know which part is the problem, since many things will happen asynchronously when you execute |
Benchmark with var stream = ss.createStream(),
self = this,
framesCount = self.framesCount;
var start1 = Date.now();
this.canvas.toBlob(function(blob) {
ss(self.socket).emit(
'newFrame',
stream,
{
framesCount: framesCount
}
);
var blobStream = ss.createBlobReadStream(blob);
blobStream.on('end', function() {
var end = Date.now();
console.log('Time1 (ms)', end - start1);
console.log('Time2 (ms)', end - start2);
});
var start2 = Date.now();
blobStream.pipe(stream);
}, 'image/jpeg', this.settings.video.quality); Will output something like:
You can see that Time2 measures the time for piping alone which consumes over 70% of the whole code snippet which is not good. |
Ah, got it. Sending data is almost finished when And data is sent gradually and asynchronously, so the main thread is not blocked. If you need more performance,
|
@nkzawa Thanks! Can you explain what |
@nkzawa And I do not want a writable stream when sending the image to the server. Can I get a readable stream only? (I suspect this because hightWaterMark is for writable streams only) |
see the document: http://nodejs.org/api/stream.html |
I see. Have implemented something like this to automatically adjust the buffer size: this.canvas.toBlob(function(blob) {
ss(self.socket).emit(
'newFrame',
stream,
{
framesCount: framesCount
}
);
var blobStream = ss.createBlobReadStream(blob, {hightWaterMark: self.hightWaterMark}),
size = 0;
blobStream.on('data', function(chunk) {
size += chunk.length;
});
blobStream.on('end', function() {
// automatically correct max buffer size for the next image frame
self.hightWaterMark = size * 1.1;
});
blobStream.pipe(stream);
}, 'image/jpeg', this.settings.video.quality); |
I'm not sure whether setting I will close the issue anyway. |
@nkzawa Thanks but sorry, I have quit this module and am using the websocket-stream one. It's pure binary and faster. |
Hello there
I experience performance issues with the following piece of code:
My goal is to send images to the server in binary. I made measurements and found out that
ss.createBlobReadStream(blob).pipe(stream);
is the slowest part.Firefox alone needs about 50ms - 60ms to pipe that blob to the server. In other words the main thread is blocked by 50ms - 60ms!
Any clues?
The text was updated successfully, but these errors were encountered: