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

Use of http package should be moved to dio #1927

Closed
lukehutch opened this issue Feb 17, 2024 · 3 comments
Closed

Use of http package should be moved to dio #1927

lukehutch opened this issue Feb 17, 2024 · 3 comments

Comments

@lukehutch
Copy link
Contributor

When I demo'd my app to the Serverpod team, numerous times queries took 1 or more seconds (the worst response time was about 8 seconds). This is for only 50 items in the database.

I have looked into this more closely, and the problem is definitely not happening on the server (total endpoint runtime is consistently low). The problem happens at this line, in serverpod_client_io.dart:

      var response = await request.close().timeout(connectionTimeout);

I have absolutely no idea why closing a request would take this long, but profiling in Dart is utterly useless and broken (I tried), and the http library is nearly impossible to properly debug because it was written back before async/await (even before null-safety and generics...).

I have had other bad experiences with http before, and I have seen numerous reports online of other people running into problems with http. The Dart team don't seem interested in rewriting it or even updating it to modern Dart.

I filed a bug about this here, but I don't anticipate seeing any action on this:

dart-lang/http#1134

The best fix for Serverpod is almost certainly to move from http to dio for sending requests to the server.

@lukehutch
Copy link
Contributor Author

lukehutch commented Feb 17, 2024

After all the work of #1928, the problem is not fixed (Dio.post shows the same erratic timing behavior, and I assume Dio is not using HttpClient at the core).

(In spite of this, it's still probably a good idea to use dio rather than http, since the http code is a mess...)

@lukehutch
Copy link
Contributor Author

I tried debugging this on the server too, at the point where the requests came in to HttpServer, but the erratic delay problem is not there either.

It looks like the delay issue is in the Android emulator. If I run with the same debug build on a physical device, against the same server instance, the response times are no longer erratic.

I'll close this, but I will leave the PR open, since the dio port is probably a worthwhile improvement.

@lukehutch
Copy link
Contributor Author

For the record, here is the reason why HTTP requests can be very slow in Flutter:

dart-lang/sdk#50868

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

Successfully merging a pull request may close this issue.

1 participant