Comments (8)
Thanks for opening this issue @DJLemkes 🙏 I have been thinking about it for a long time and am kinda split between multiple approaches.
One problem that we will face when encoding Content using ZStreams is that — it will be very slow even for smaller Http Requests and Responses where chunking or streaming isn't necessary. HttpObjectAggregator does a really awesome job in terms of performance for small to medium-sized requests (up to a few Kbs). But as soon as we start dealing with file uploads or downloads or requesting using multi-part data etc. the HttpObjectAggregator
doesn't scale.
from zio-http.
I think that's a valid concern; have been thinking about that myself as well.
So ideally, you'd offer an API that is tailored to your use case I think? That is, if you know you'll only be doing small requests you'd just get the request content as a String
. Don't have an idea on how to do that though. And whether that is desirable.
On the other hand, we can tune the chunk size for the Netty Http decoder like here, such that in most cases the HttpObjectAggregator
won't have that much aggregation to do.
I can try and see if I can get a small PoC ready this week. It's all speculation until we run some benchmarks. Quite sure that it'll be worse, but the question is how much.
What are the other approaches you were considering?
from zio-http.
We can split the problem of reading body
into two concerns —
-
Request — This is can be done in three ways
a. Only expose a ZStream based API for reading requestbody
, this is what Http4s is also doing. Performance is going to be really poor here. Especially if you start doing any form of aggregation (based on our internal benchmarks it can be up to 5x slower than Netty's Object Aggregator).b. Use a server configuration at startup to decide if you want to expose a ZStream API vs using ObjectAggregator. This is a classical approach and might just solve both use cases. Problem is that the dev will always have to perform a check inside the router to see if
body
is exposed as a stream or is "completely" available.c. Provide a special Http constructor to read requests as a stream eg
Http.chunked.collect
or something else which guarantees that the data is available as a stream. -
Response — This is easy to solve, because the developer can choose to use
Complete
vsChunked
content while writing the response.
May be we can start by at least providing support for streaming responses?
from zio-http.
Yes, nice layout of the problem. Actually with this issue I only meant looking at the request side of things. Turns out that might just the hardest part, haha.
I took a small shot at direction 1a
for the Request in #147. Very rough around the edges, but please have a look. Yes, it is slower but it's not as bad as I expected actually. One major downside of this streaming approach that provides backpressure to the socket is that you always have to consume the request body to know for sure you're fully processing the request. With GET
requests in most cases it'll work without consuming the stream but it's not a guarantee. This makes Http.collect
more tricky to work with as consuming/discarding the body will always require a Http.collectM
I do really like idea 1c
although then you still have to know at Netty init time if you want to use the HttpObjectAggregator
or not.
As for the response side of things; that actually sounds like a nice first step. Are you already working on that?
from zio-http.
@DJLemkes I am working on the Chunked Responses.
from zio-http.
Made a small update in #147 that makes server streaming requests configurable like proposed by @tusharmath in 1b. It might not be the prettiest in terms of user experience as he already said. But in this case it definitely helps running benchmarks in the same context :).
from zio-http.
Another update in #147 based on the latest work on streaming responses (which are awesome!). Performance of streaming is nearly (~5%) on par of non-streaming.
@amitksingh1490 it also fixes a bug in the non-streaming handler where subsequent requests to the same endpoint were causing Netty to throw exceptions (unexpected message type: DefaultHttpResponse, state: 1
). I can trigger that by sending multiple requests to e.g. the /foo
endpoint in HelloWordAdvanced
app.
from zio-http.
Request Streaming is supported in zio-http v1.0.0.0.0-RC27
and v2.0.0.0-RC5+
from zio-http.
Related Issues (20)
- [openapi] fromEndpoints fail with an unexpected None.get
- Accept Routes with arbitrary error type in `PathCodec#/`
- Endpoint: add query codec validation for max/min length and regex
- CorsConfig 'allowedHeaders' parameter generates an 'Access-Control-Expose-Headers' header HOT 1
- StackOverflowError when too many "optional" query parameters defined for Endpoint HOT 4
- Unseal `TextCodec` to allow custom query parameter enc/decoding HOT 2
- Warning header loses original exception when that exception contains invalid-for-netty-headers characters
- Generic `ServerSentEvents`
- Support receiving `ServerSentEvents` in the (Endpoint) client HOT 3
- Remove internal usage of warning header
- ZClient memory leaks finalizers on each request HOT 4
- Improve ZClient UX with regards to Scope
- Simplify `EncoderDecoder`
- Improve `Literal` path matching via state machine
- Http Server keeps application alive when it should exit HOT 6
- [gen] add support for type aliases (newtype / opaque type) when generating code from spec
- HTML Templates can't emit attributes without values
- OpenApiGen crashes with stack overflow on recursive case classes
- CRLF stripped in TextFields inside Multipart request HOT 1
- WebSockets don't work with `.enableRequestStreaming` HOT 1
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 zio-http.