Comments (9)
Thank you for reporting it.
Could you tell me the details of how you benchmarked?
I want to know which part is the problem, since many things will happen asynchronously when you execute ss.createBlobReadStream(blob).pipe(stream);
.
from socket.io-stream.
Benchmark with Date.now()
and console.log
.
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:
Time1 (ms) 160
Time2 (ms) 124
You can see that Time2 measures the time for piping alone which consumes over 70% of the whole code snippet which is not good.
from socket.io-stream.
Ah, got it.
Sending data is almost finished when end
event happens, which means Time2
includes time of network communications.
And data is sent gradually and asynchronously, so the main thread is not blocked.
If you need more performance, highWaterMark
option may help.
ss.createStream({hightWaterMark: 16 * 1024});
ss.createBlobReadStream(blob, {hightWaterMark: 16 * 1024});
from socket.io-stream.
@nkzawa Thanks! Can you explain what highWaterMark
means? Where it is documented?
from socket.io-stream.
@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)
from socket.io-stream.
highWaterMark
is both for readable and writable stream.
see the document: http://nodejs.org/api/stream.html
from socket.io-stream.
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);
from socket.io-stream.
I'm not sure whether setting hightWaterMark
higher than a blob size is good or not. You should try.
I will close the issue anyway.
from socket.io-stream.
@nkzawa Thanks but sorry, I have quit this module and am using the websocket-stream one. It's pure binary and faster.
from socket.io-stream.
Related Issues (20)
- server > client HOT 1
- Simpler API
- MediaStream HOT 11
- Can you upload a folder?
- events.js:62 Uncaught Error: Uncaught, unspecified "error" event. (Authentication error) HOT 1
- Able to send/receive a native browser stream HOT 1
- An error when using Socket.io-stream with Electron.
- A port to other languages
- Stream interrupted file
- Uncaught TypeError: Cannot read property '_read' of null HOT 3
- Server dont recive emit or client dont emit HOT 3
- Send audio file from node.js server to another node.js server
- Client iOS
- This version of debug is vulnerable to ReDos attacks HOT 3
- In browser console getting error
- [Deprecation] SharedArrayBuffer
- add a settimeout to it to reduce cpu consumption
- Unfortunately there is no support for rooms and broadcasting for now.
- Could not create stream object. Getting Cannot read properties of undefined error.
- donot work with ubuntu 22.04
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-stream.