Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
edwintorok committed Jul 26, 2023
1 parent a284e6b commit 87363bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ocaml/loadgen/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(executable
(name speculative)
(name loadgen)
(libraries xapi-client xapi_version rresult faraday bigstringaf bigstring-unix polly xapi-stdext-unix zero_http)
)

35 changes: 26 additions & 9 deletions ocaml/loadgen/loadgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,45 @@ let write_calls n call uri_path conv =

let n = 1000

let conn = Speculative.connect Unix.(ADDR_INET (inet_addr_loopback, 8000))
let t = Speculative.init ()

let rpc call : Rpc.response Speculative.Freer.Monad.t =
let conn = Speculative.connect t Unix.(ADDR_INET (inet_addr_loopback, 8000))

module I =
struct
type !'a t = Real of 'a | Blocked
let run = function | Real x -> x | Blocked -> failwith "TODO"
end

module F = Freer.Make(I)
module M = struct
include F
let (>>|) x y = fmap y x
end

let rpc call : Rpc.response M.t =
(* write_calls n call "jsonrpc" Jsonrpc.string_of_call;
write_calls n call "RPC2" Xmlrpc.string_of_call; *)
let str = Jsonrpc.string_of_call call in
let buf = Bytes.create 8192 in
let open M in
let read_response = M.lift I.Blocked in
Speculative.Connection.write conn str;
read_response
(*let buf = Bytes.create 8192 in
let decode_response nread =
Bytes.sub_string buf 0 nread |> Jsonrpc.response_of_string
in
let open Speculative.Freer in
let open M in
let read_response = decode_response <$> Speculative.read conn buf in
Speculative.write conn str >>> read_response
Speculative.write conn str >>> read_response *)

module C = Client.ClientF (Speculative.Freer.Monad)
module C = Client.ClientF (M)

let () =
(* we need to loop here, because jsonrpc would carry an ID that needs to be changed with each request *)
let version = Xapi_version.version in
let _ =
C.Session.login_with_password ~rpc ~uname:"root" ~pwd:"foo" ~version
~originator:__FILE__
|> Speculative.run conn
~originator:__FILE__ |> M.run
in
()
Speculative.run t
3 changes: 1 addition & 2 deletions ocaml/loadgen/speculative.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Ze = Zero_http.Zero_events

let () = Sys.set_signal Sys.sigpipe Sys.Signal_ignore

let event_connect = Ze.register_simple_span "http.connect"
Expand Down Expand Up @@ -268,7 +267,7 @@ let run ?(receive_buffer_size = 16384) t =
requests


let () =
let test_get () =
let t = init () in
let host = "perfuk-18-06d.xenrt.citrite.net" in
let addr = (Unix.getaddrinfo host "80" [] |> List.hd).Unix.ai_addr in
Expand Down

0 comments on commit 87363bf

Please sign in to comment.