Should fully consume the InputStream of InputStreamResponseListener before close it?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Should fully consume the InputStream of InputStreamResponseListener before close it?

Đạt Cao Mạnh
Hi guys,

I kinda see this pattern frequently in Apache HttpClient
Please note that if response content is not fully consumed the underlying connection cannot be safely re-used and will be shut down and discarded by the connection manager. 

Wondering it will be the same pattern need to apply when uses InputStreamResponseListener? Based on Javadoc 
If the consumer is faster than the producer, then the consumer will block with the typical InputStream.read() semantic. If the consumer is slower than the producer, then the producer will block until the client consumes
So I kinda assume that close() without fully consume the InputStream will be better (since producer doesn't need to put more data into the stream). Is that true?

Thanks!
------
Cao Mạnh Đạt

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Should fully consume the InputStream of InputStreamResponseListener before close it?

Greg Wilkins

Cao,

The answer is "it depends".

Closing the stream will result in the connection being closed and not reused for other requests.  Making new connections can be expensive, especially if SSL is used, plus new connections are often slower than old connections as their flow control windows are not well sized.

So fully consuming some content so a connection may be reused may be cheaper than closing... but if generating the data is expensive or there is a lot of data yet  to come, then perhaps not.....

so your mileage may vary!







On Wed, 9 Oct 2019 at 01:56, Đạt Cao Mạnh <[hidden email]> wrote:
Hi guys,

I kinda see this pattern frequently in Apache HttpClient
Please note that if response content is not fully consumed the underlying connection cannot be safely re-used and will be shut down and discarded by the connection manager. 

Wondering it will be the same pattern need to apply when uses InputStreamResponseListener? Based on Javadoc 
If the consumer is faster than the producer, then the consumer will block with the typical InputStream.read() semantic. If the consumer is slower than the producer, then the producer will block until the client consumes
So I kinda assume that close() without fully consume the InputStream will be better (since producer doesn't need to put more data into the stream). Is that true?

Thanks!
------
Cao Mạnh Đạt
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Should fully consume the InputStream of InputStreamResponseListener before close it?

Đạt Cao Mạnh
Hi Greg, 

I just want to confirm, close() here is called on InputStream. By calling that it will close the underlying connection too? And it even true in case of HTTP/2?

Thanks a lot!

Vào Th 4, 9 thg 10, 2019 lúc 05:28 Greg Wilkins <[hidden email]> đã viết:

Cao,

The answer is "it depends".

Closing the stream will result in the connection being closed and not reused for other requests.  Making new connections can be expensive, especially if SSL is used, plus new connections are often slower than old connections as their flow control windows are not well sized.

So fully consuming some content so a connection may be reused may be cheaper than closing... but if generating the data is expensive or there is a lot of data yet  to come, then perhaps not.....

so your mileage may vary!







On Wed, 9 Oct 2019 at 01:56, Đạt Cao Mạnh <[hidden email]> wrote:
Hi guys,

I kinda see this pattern frequently in Apache HttpClient
Please note that if response content is not fully consumed the underlying connection cannot be safely re-used and will be shut down and discarded by the connection manager. 

Wondering it will be the same pattern need to apply when uses InputStreamResponseListener? Based on Javadoc 
If the consumer is faster than the producer, then the consumer will block with the typical InputStream.read() semantic. If the consumer is slower than the producer, then the producer will block until the client consumes
So I kinda assume that close() without fully consume the InputStream will be better (since producer doesn't need to put more data into the stream). Is that true?

Thanks!
------
Cao Mạnh Đạt
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
--
Best regards,
Cao Mạnh Đạt

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Should fully consume the InputStream of InputStreamResponseListener before close it?

Greg Wilkins

Close on the input stream will not close the connection.  But it will cause the server that is writing content to have a broken pipe exception and then they will close the connection.

If the server is not confident the request/response cycle has completed normally, then it will close the connection. ditto for the client.


On Wed, 9 Oct 2019 at 17:28, Đạt Cao Mạnh <[hidden email]> wrote:
Hi Greg, 

I just want to confirm, close() here is called on InputStream. By calling that it will close the underlying connection too? And it even true in case of HTTP/2?

Thanks a lot!

Vào Th 4, 9 thg 10, 2019 lúc 05:28 Greg Wilkins <[hidden email]> đã viết:

Cao,

The answer is "it depends".

Closing the stream will result in the connection being closed and not reused for other requests.  Making new connections can be expensive, especially if SSL is used, plus new connections are often slower than old connections as their flow control windows are not well sized.

So fully consuming some content so a connection may be reused may be cheaper than closing... but if generating the data is expensive or there is a lot of data yet  to come, then perhaps not.....

so your mileage may vary!







On Wed, 9 Oct 2019 at 01:56, Đạt Cao Mạnh <[hidden email]> wrote:
Hi guys,

I kinda see this pattern frequently in Apache HttpClient
Please note that if response content is not fully consumed the underlying connection cannot be safely re-used and will be shut down and discarded by the connection manager. 

Wondering it will be the same pattern need to apply when uses InputStreamResponseListener? Based on Javadoc 
If the consumer is faster than the producer, then the consumer will block with the typical InputStream.read() semantic. If the consumer is slower than the producer, then the producer will block until the client consumes
So I kinda assume that close() without fully consume the InputStream will be better (since producer doesn't need to put more data into the stream). Is that true?

Thanks!
------
Cao Mạnh Đạt
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
--
Best regards,
Cao Mạnh Đạt
_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users


--

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Should fully consume the InputStream of InputStreamResponseListener before close it?

Đạt Cao Mạnh
Oh that totally makes sense! Thanks a lot for clarifying!

_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users