Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max connection, concurrent requests #515

Closed
sm2017 opened this issue Jan 3, 2021 · 3 comments
Closed

Max connection, concurrent requests #515

sm2017 opened this issue Jan 3, 2021 · 3 comments

Comments

@sm2017
Copy link

sm2017 commented Jan 3, 2021

I have some question that asked before in stack overflow without good responses, May be it's a feature request I'm not sure, Please help me

I have an instance of Client in my application, it is the only client that I send request to the server, Today I see that there is a client.close() method, If you call it , you cannot send request anymore.

I want to know :

1. How many connections can be created by a Client in flutter

In the official document we have

The interface for HTTP clients that take care of maintaining persistent connections across multiple requests to the same server.

So I think Client create a connection and do it best to keep it alive, I think If the server cannot support persistent connections or close the connection, The Client will create another connection on the next request, Right?
Also I think there is no connection pooling and If I want to have 2 connection simultaneously I must create 2 Client instace
What happens if we have multiple host, for instance s1.example.com , s2.example.com ,another.com:8080

2. What will happen if I have a global Client and we lose connection, i.e: disconnecting from the internet

I think as we have persistent connections for short network issue, the connection is not lost, but for long issues or OS detection it will lost but for the next request client will create another connection

3. How many concurrent requests can be sent by a Client?

As I think a client has only a persisted connection (I'm not sure about multiple hostname, May be a persisted connection per hostname) , It queue request and we cannot have concurrent requests

4. Is using a global Client a bad idea?

What happened if I never call client.close(), and use an instance of Client globally, I think downloading and uploading large files will block subsequent requests

@guilherme-v
Copy link

Nice question! I have the same doubt here, can anyone help?

@sm2017
Copy link
Author

sm2017 commented Jan 13, 2021

@guilherme-v I have some new experience with Client I figured out that we can t have concurrent requests, I test both concurrent
uploading and downloading large files with a single Client
I just cannot understand why there is no way to cancel a single request and we must call client.close() ?

@natebosch
Copy link
Member

So I think Client create a connection and do it best to keep it alive, I think If the server cannot support persistent connections or close the connection, The Client will create another connection on the next request, Right?

I don't think we do anything in this package to hold connections.

The dart:io class HttpClient is used underneat the package:http Client on the VM. That class does reuse connections.
https://api.dart.dev/stable/2.10.4/dart-io/HttpClient-class.html

I just cannot understand why there is no way to cancel a single request and we must call client.close() ?

Tracked at #424

I'm going to close this issue since it relates to the SDK and not this package, and the aborting API is tracked in #424.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants