cronet 0.0.2 cronet: ^0.0.2 copied to clipboard
Experimental Cronet dart bindings.
Experimental Cronet Dart bindings #
This package binds to Cronet's native API to expose them in Dart.
This is an HTTP Client Package with almost the same API as dart:io
. By comparison, package:cronet
is capable of serving about 4 to 5 times more parallel network requests than dart:io
and on par in making sequential network requests.
This is a GSoC 2021 project.
Supported Platforms #
Currently, 64 bit Desktop Platforms (Linux, Windows and MacOS) are supported.
Requirements #
- Dart SDK 2.12.0 or above.
- CMake 3.15 or above. (If on windows, Visual Studio 2019 with C++ tools)
- C++ compiler. (g++/clang/msvc)
Usage #
-
Add package as a dependency in your
pubspec.yaml
. -
Run this from the
root
of your project.Dart CLI
dart pub get dart run cronet:setup # Downloads the cronet binaries.
-
Import
import 'package:cronet/cronet.dart';
Note: Internet connection is required to download cronet binaries.
Example #
final client = HttpClient();
client
.getUrl(Uri.parse('http://info.cern.ch/'))
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
response.transform(utf8.decoder).listen((contents) {
print(contents);
},
onDone: () => print(
'Done!'));
});
See the API comparison with dart:io
.
Run Example #
cd example
dart run cronet:setup # Downloads the cronet binaries.
dart run
Run Tests #
dart pub get
dart run cronet:setup # Downloads the cronet binaries.
dart test --platform vm
You can also verify your cronet binaries using dart run cronet:setup verify
.
Make sure to have cmake 3.15
.
Benchmarking #
See benchmark summary and extensive reports for comparison with dart:io
.
dart pub get
dart run cronet:setup # Downloads the cronet binaries.
dart run benchmark/latency.dart # For sequential requests benchmark.
dart run benchmark/throughput.dart # For parallel requests benchmark.
dart run benchmark/run_all.dart # To run all the benchmarks and get reports.
All the benchmarking scripts take test server url as a cli argument. throughput.dart
and run_all.dart
also take N
where 2^N
is the maximum possible parallel requests and the max duration for each run to complete in seconds.
To know how to setup local test servers, read benchmarking guide.
Note: Test results may get affected by: https://github.com/google/cronet.dart/issues/11.
Building Your Own #
-
Make sure you've downloaded your custom version of cronet shared library and filename follows the pattern
cronet.86.0.4240.198.<extension>
with a prefixlib
if onlinux
. Else, you can build cronet from source using the provided instuctions. Then copy the library to the designated folder. For linux, the files are under.dart_tool/cronet/linux64
. -
Run
dart run cronet:setup build
from the root of your project.
Note for Windows: Run step 2
from x64 Native Tools Command Prompt for VS 2019
shell.