forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: measure threadpool overhead too and see where we stop scaling linearly with threads, because PAM alone is a lot faster than what we get from the threadpool or the threaded test.
- Loading branch information
1 parent
e714a19
commit 050adfa
Showing
5 changed files
with
125 additions
and
4 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
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
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
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
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,49 @@ | ||
let () = | ||
let nthreads = ref 8 in | ||
let user = ref "" in | ||
let password = ref "" in | ||
let perthread = ref 4 in | ||
(* TODO: use bechamel to measure speed! *) | ||
Arg.parse [ | ||
"--threads", Arg.Set_int nthreads, "Number of threads to use" | ||
; "--username", Arg.Set_string user, "Username for test" | ||
; "--password", Arg.Set_string password, "Password for test" | ||
; "--perthread", Arg.Set_int perthread, "Authentication attempts per thread" | ||
] (fun _ -> raise (Arg.Bad "Unexpected argument")) "Usage"; | ||
|
||
let start_semaphore = Semaphore.Counting.make !nthreads in | ||
let finish_semaphore = Semaphore.Counting.make 0 in | ||
|
||
let threads = Array.init !nthreads @@ Thread.create @@ fun _ -> | ||
let handle = Pam.authenticate_start () in | ||
let finally () = Pam.authenticate_stop handle in | ||
Fun.protect ~finally @@ fun () -> | ||
|
||
Semaphore.Counting.acquire start_semaphore; | ||
|
||
for _ = 1 to !perthread do | ||
Pam.authorize handle !user !password; | ||
done; | ||
|
||
Semaphore.Counting.release finish_semaphore | ||
in | ||
|
||
let start () = | ||
for _ = 1 to !nthreads do | ||
Semaphore.Counting.release start_semaphore | ||
done | ||
in | ||
|
||
let wait () = | ||
for _ = 1 to !nthreads do | ||
Semaphore.Counting.acquire finish_semaphore | ||
done | ||
in | ||
|
||
let dt = Mtime_clock.counter () in | ||
start (); | ||
wait (); | ||
let speed = float (!nthreads * !perthread) /. (Mtime_clock.count dt |> Mtime.Span.to_s) in | ||
Printf.printf "Auth/s: %.3f\n" speed; | ||
|
||
Array.iter Thread.join threads |