-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from Cjen1/benchmark
Add echo benchmark test
- Loading branch information
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(executable | ||
(name echo_bench) | ||
(libraries lwt.unix capnp-rpc capnp-rpc-lwt capnp-rpc-net capnp-rpc-unix logs.fmt) | ||
(flags (:standard -w -53-55))) | ||
|
||
(rule | ||
(targets echo_api.ml echo_api.mli) | ||
(deps echo_api.capnp) | ||
(action (run capnpc -o %{bin:capnpc-ocaml} %{deps}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Api = Echo_api.MakeRPC(Capnp_rpc_lwt) | ||
|
||
open Lwt.Infix | ||
open Capnp_rpc_lwt | ||
|
||
(*-- Server ----------------------------------------*) | ||
let local = | ||
let module Echo = Api.Service.Echo in | ||
|
||
Echo.local @@ object | ||
inherit Echo.service | ||
|
||
method ping_impl params release_param_caps = | ||
let open Echo.Ping in | ||
let msg = Params.msg_get params in | ||
release_param_caps (); | ||
let response, results = Service.Response.create Results.init_pointer in | ||
Results.reply_set results ("echo:" ^ msg); | ||
Service.return response | ||
end | ||
|
||
(*-- Client ----------------------------------------*) | ||
module Echo = Api.Client.Echo | ||
|
||
let ping t msg = | ||
let open Echo.Ping in | ||
let request, params = Capability.Request.create Params.init_pointer in | ||
Params.msg_set params msg; | ||
Capability.call_for_value_exn t method_id request >|= Results.reply_get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@0xb13fc2f2a4c1d65b; | ||
|
||
interface Echo { | ||
ping @0 (msg :Text) -> (reply :Text); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
open Lwt.Infix | ||
|
||
open Capnp_rpc_lwt | ||
|
||
let () = | ||
Logs.set_level (Some Logs.Info); | ||
Logs.set_reporter (Logs_fmt.reporter ()) | ||
|
||
let run_client service = | ||
let n = 100000 in | ||
let ops = List.init n (fun i -> | ||
let payload = Int.to_string i in | ||
let desired_result = "echo:" ^ payload in | ||
fun () -> | ||
Echo.ping service payload >|= fun res -> | ||
assert (res = desired_result) | ||
) in | ||
let st = Unix.gettimeofday () in | ||
Lwt_list.iter_p (fun v -> v ()) ops >>= fun () -> | ||
let ed = Unix.gettimeofday () in | ||
let rate = (Int.to_float n) /. (ed -. st) in | ||
Logs.info (fun m -> m "rate = %f" rate ); | ||
Lwt.return_unit | ||
|
||
let secret_key = `Ephemeral | ||
let listen_address = `TCP ("127.0.0.1", 7000) | ||
|
||
let start_server () = | ||
let config = Capnp_rpc_unix.Vat_config.create ~secret_key ~serve_tls:false listen_address in | ||
let service_id = Capnp_rpc_unix.Vat_config.derived_id config "main" in | ||
let restore = Capnp_rpc_net.Restorer.single service_id Echo.local in | ||
Capnp_rpc_unix.serve config ~restore >|= fun vat -> | ||
Capnp_rpc_unix.Vat.sturdy_uri vat service_id | ||
|
||
let () = | ||
Lwt_main.run begin | ||
start_server () >>= fun uri -> | ||
Fmt.pr "Connecting to echo service at: %a@." Uri.pp_hum uri; | ||
let client_vat = Capnp_rpc_unix.client_only_vat () in | ||
let sr = Capnp_rpc_unix.Vat.import_exn client_vat uri in | ||
Sturdy_ref.connect_exn sr >>= fun proxy -> | ||
run_client proxy | ||
end |
Empty file.