-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Description
The following code will send the data BEFORE
6s:
const util = require('node:util');
const HANDLER_HIGHWATERMARK = Symbol.for(
'aws.lambda.runtime.handler.streaming.highWaterMark',
);
const handler = async (event, responseStream, context) => {
responseStream.setContentType('text/html; charset=utf-8');
responseStream.write("Thinking...");
responseStream.write("a".repeat(64 * 1024));
setTimeout(function() {
responseStream.write("b".repeat(64 * 1024));
}, 3000);
setTimeout(function() {
responseStream.write("After 6s");
responseStream.end();
}, 6000);
};
handler[HANDLER_HIGHWATERMARK] = 512;
exports.handler = awslambda.streamifyResponse(handler, {
highWaterMark: 512
}
);
The following code will only send data AFTER
6s.
const util = require('node:util');
const HANDLER_HIGHWATERMARK = Symbol.for(
'aws.lambda.runtime.handler.streaming.highWaterMark',
);
const handler = async (event, responseStream, context) => {
responseStream.setContentType('text/html; charset=utf-8');
responseStream.write("Thinking...");
responseStream.write("a".repeat(1 * 1024));
setTimeout(function() {
responseStream.write("b".repeat(1 * 1024));
}, 3000);
setTimeout(function() {
responseStream.write("After 6s");
responseStream.end();
}, 6000);
};
handler[HANDLER_HIGHWATERMARK] = 512;
exports.handler = awslambda.streamifyResponse(handler, {
highWaterMark: 512
}
);
From what I tested, the default highWaterMark
is 64Kb
, but there is no way to override it to be lower, I tried two different ways to do it.
This causes weird issues where I can't send some tiny text and then wait 6s to send more data, it will be sent as a single chunk only after 6s.
This issue was initially discovered at H4ad/serverless-adapter#166
Metadata
Metadata
Assignees
Labels
No labels