Skip to content

Commit

Permalink
http-lib: prepare test client for more commands
Browse files Browse the repository at this point in the history
Current behaviour for displaying stats is done with the --perf parameter

Signed-off-by: Pau Ruiz Safont <[email protected]>
  • Loading branch information
psafont committed Oct 9, 2024
1 parent ed96146 commit 3bef65f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
50 changes: 23 additions & 27 deletions ocaml/libs/http-lib/test_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ open Safe_resources

let user_agent = "test_client"

(* To do:
1. test with and without SSL
2. test with n parallel threads
3. make sure xapi still works
4. make xapi able to read stats
*)
let ip = ref "127.0.0.1"

let port = ref 8080

let use_ssl = ref false

let use_fastpath = ref false

let use_framing = ref false

let with_connection ip port f =
let inet_addr = Unix.inet_addr_of_string ip in
Expand Down Expand Up @@ -108,30 +111,10 @@ let sample n f =
done ;
!p

let _ =
let ip = ref "127.0.0.1" in
let port = ref 8080 in
let use_ssl = ref false in
let use_fastpath = ref false in
let use_framing = ref false in
Arg.parse
[
("-ip", Arg.Set_string ip, "IP to connect to")
; ("-p", Arg.Set_int port, "port to connect")
; ("-fast", Arg.Set use_fastpath, "use HTTP fastpath")
; ("-frame", Arg.Set use_framing, "use HTTP framing")
; ("--ssl", Arg.Set use_ssl, "use SSL rather than plaintext")
]
(fun x -> Printf.fprintf stderr "Ignoring unexpected argument: %s\n" x)
"A simple test HTTP client" ;
let perf () =
let use_fastpath = !use_fastpath in
let use_framing = !use_framing in
let transport = if !use_ssl then with_stunnel else with_connection in
(*
Printf.printf "Overhead of timing: ";
let overhead = sample 10 (fun () -> per_nsec 1. (fun () -> ())) in
Printf.printf "%s ops/sec\n" (Normal_population.to_string overhead);
*)
Printf.printf "1 thread non-persistent connections: " ;
let nonpersistent =
sample 1 (fun () ->
Expand Down Expand Up @@ -183,3 +166,16 @@ let _ =
)
in
Printf.printf "%s RPCs/sec\n%!" (Normal_population.to_string thread_persistent)

let () =
Arg.parse
[
("-ip", Arg.Set_string ip, "IP to connect to")
; ("-p", Arg.Set_int port, "port to connect")
; ("-fast", Arg.Set use_fastpath, "use HTTP fastpath")
; ("-frame", Arg.Set use_framing, "use HTTP framing")
; ("--ssl", Arg.Set use_ssl, "use SSL rather than plaintext")
; ("--perf", Arg.Unit perf, "Collect performance stats")
]
(fun x -> Printf.fprintf stderr "Ignoring unexpected argument: %s\n" x)
"A simple test HTTP client"
4 changes: 2 additions & 2 deletions ocaml/libs/http-lib/test_client_server.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
== Bring server up
$ trap 'kill $(jobs -p)' EXIT
$ ./test_server.exe &
$ sleep 1
$ sleep 0.1

== Normal
$ ./test_client.exe > /dev/null
$ ./test_client.exe --perf > /dev/null

0 comments on commit 3bef65f

Please sign in to comment.