aws / aws/aws-lambda-nodejs-runtime-interface-client

Override `highWaterMark` didn't work

Đang mở
#94 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
224
Fork
60
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

The following code will send the data `BEFORE` 6s:

```js
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.

```js
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 https://github.com/H4ad/serverless-adapter/issues/166

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu tại entry point awslambda.streamifyResponse và theo dõi cách tùy chọn highWaterMark cùng handler symbol được sử dụng. Tái hiện hai ví dụ và xác minh rằng giá trị được cấu hình là 512 sẽ phân phối các lần ghi sớm trước các lần ghi bị trì hoãn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
node.js, typescript
Lĩnh vực
backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.