Skip to content

CP-32622: avoid using select and instead use epoll #4877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions ocaml/libs/http-svr/buf_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ let is_full ic = ic.cur = 0 && ic.max = Bytes.length ic.buf
let fill_buf ~buffered ic timeout =
let buf_size = Bytes.length ic.buf in
let fill_no_exc timeout len =
let l, _, _ = Unix.select [ic.fd] [] [] timeout in
if List.length l <> 0 then (
let n = Unix.read ic.fd ic.buf ic.max len in
ic.max <- n + ic.max ;
if n = 0 && len <> 0 then raise Eof ;
n
) else
-1
Unix.setsockopt_float ic.fd Unix.SO_RCVTIMEO timeout ;
let result =
try
let n = Unix.read ic.fd ic.buf ic.max len in
ic.max <- n + ic.max ;
if n = 0 && len <> 0 then raise Eof ;
n
with Unix.Unix_error (Unix.EAGAIN, _, _) -> -1
in
Unix.setsockopt_float ic.fd Unix.SO_RCVTIMEO 0. ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'd better use finally to ensure that this timeout is reset in case of any exception (only one kind is caught above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every read on ic.fd seems to go through here, and each read is preceded by setting a timeout, so I don't think we even need to reset the timeout, just drop this line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more reads in http.ml but they also set a socket timeout. Will need to check the other callers too.

result
in
(* If there's no space to read, shift *)
if ic.max = buf_size then shift ic ;
Expand Down
2 changes: 1 addition & 1 deletion ocaml/libs/stunnel/stunnel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ let rec retry f = function
try f ()
with Stunnel_initialisation_failed ->
(* Leave a few seconds between each attempt *)
ignore (Unix.select [] [] [] 3.) ;
Thread.delay 3. ;
retry f (n - 1)
)

Expand Down
4 changes: 2 additions & 2 deletions ocaml/squeezed/src/squeeze_xen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ let make_host ~verbose ~xc =
1024L
<> 0L
do
ignore (Unix.select [] [] [] 0.25)
Thread.delay 0.25
done ;

(* Some VMs are considered by us (but not by xen) to have an
Expand Down Expand Up @@ -857,7 +857,7 @@ let io ~xc ~verbose =
(fun domid kib ->
execute_action ~xc {Squeeze.action_domid= domid; new_target_kib= kib}
)
; wait= (fun delay -> ignore (Unix.select [] [] [] delay))
; wait= (fun delay -> Thread.delay delay)
; execute_action= (fun action -> execute_action ~xc action)
; target_host_free_mem_kib
; free_memory_tolerance_kib
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xe-cli/newcli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ let main_loop ifd ofd permitted_filenames =
with
| Unix.Unix_error (_, _, _)
when !delay <= long_connection_retry_timeout ->
ignore (Unix.select [] [] [] !delay) ;
Thread.delay !delay ;
delay := !delay *. 2. ;
keep_connection ()
| e ->
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xenopsd/cli/xn.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ let raw_console_proxy sockaddr =
(fun () -> Unix.close s)
with
| Unix.Unix_error (_, _, _) when !delay <= long_connection_retry_timeout ->
ignore (Unix.select [] [] [] !delay) ;
Thread.delay !delay ;
delay := !delay *. 2. ;
keep_connection ()
| e ->
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xenopsd/xc/memory_breakdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ let print_memory_field_values xc xs =
flush stdout

(** Sleeps for the given time period in seconds. *)
let sleep time_period_seconds = ignore (Unix.select [] [] [] time_period_seconds)
let sleep time_period_seconds = Thread.delay time_period_seconds

(** Prints a header line of memory field names, and then periodically prints a
line of memory field values. *)
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xenopsd/xc/memory_summary.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let _ =
let finished = ref false in
while not !finished do
finished := !delay < 0. ;
if !delay > 0. then ignore (Unix.select [] [] [] !delay) ;
if !delay > 0. then Thread.delay !delay ;
flush stdout ;
let physinfo = Xenctrl.physinfo xc in
let one_page = 4096L in
Expand Down