dart-lang / http2

A HTTP/2 implementation for dart.
https://pub.dev/packages/http2
BSD 3-Clause "New" or "Revised" License
153 stars 46 forks source link

http2 seems to be slow #69

Open KMantas opened 4 years ago

KMantas commented 4 years ago

Hi

I have tested speed of http2 library and it is much slower comparing to http. I tested with client and server being on my local. Server is written in Go and client in Dart. To downloaded 100mb file with HttpClient it takes 4s and http2 takes 15s. I faced this issue with GRPC. We are downloading files with GRPC streams and speed depending on how far the server is, can be 8 times slower comparing to http download. I was trying to isolate the issue and it seems http2 package seems to be the main problem. I have Dart VM version: 2.8.4 and tested with http2: ^1.0.0 http: ^0.12.2

I used the code from "minimal example" to download file with http2. Is there a way to improve speed?

FrantisekGazo commented 3 years ago

Any update on this?

thamarakshan-pilla commented 2 years ago

Any update on this yet??

Neronse commented 2 years ago

Seems like problem is not in http2 package. I noticed that sending photo is slow too. Sending bytes to outgoing stream is fast enough, but when we start listen incoming stream, first header frame received only after 10s+. Looks like problem may be in raw socket. I have found this issue for dart socket https://github.com/dart-lang/sdk/issues/48210, may be where the same problem.

I also want to note that the problem is serious for http 2 in dart. All native solutions are faster.

UPD: My problem wasnt in http2 package, or socket. I am using Dio and write http2 adapter. And all open source adapters implemented like this https://github.com/flutterchina/dio/blob/master/plugins/http2_adapter/lib/src/http2_adapter.dart#L75 They are sending data messages with 1 byte inside. When i refactored this code, speed of sending becomes `normal.

 final bytes = BytesBuilder(copy: false);
      final completer = Completer<Uint8List>.sync();
      requestStream.listen(
        bytes.add,
        onError: completer.completeError,
        onDone: () => completer.complete(bytes.takeBytes()),
        cancelOnError: true,
      );
      final collectedBytes = await completer.future;
      stream.sendData(collectedBytes);