awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.74k stars 342 forks source link

Support Lambda response streaming #318

Open jabrks opened 3 months ago

jabrks commented 3 months ago

It would be great if LLRT supported Lambda response streaming as per https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html#runtimes-custom-response-streaming.

jabrks commented 3 months ago

I had a go at implementing this myself (my Rust isn't quite up to scratch but the code that interacts with the Lambda runtime API is written in TypeScript for the moment) but I don't think we have a way to stream a request body in LLRT currently. I would've ordinarily used the http API in Node.js but that isn't implemented here with a recommendation to use fetch instead, which only seems to allow a string, Array, ArrayBuffer or Uint8Array.

I'd be happy to take another look if there's a preferred way forward here?

richarddavison commented 3 months ago

Hi @jabrks. We want to support response streams but first we have to implement native streaming for performance reasons https://github.com/awslabs/llrt/issues/178

gc-victor commented 3 months ago

Hey @richarddavison, have you considered web-streams-polyfill? It's used in Lagon.

References:

richarddavison commented 3 months ago

Thanks for the suggestion but we already have a streams polyfill but that won't perform as well as we desire due to lack of a JIT. Basically every byte that flows through a stream implemented will cause multiple function calls, branches, allocations etc.

jabrks commented 3 months ago

Thanks @richarddavison, I'll sit tight for now in that case!