Skip to content

Commit c7dde27

Browse files
committed
bench + exception managment + various
1 parent 9e1c352 commit c7dde27

File tree

9 files changed

+4038
-4048
lines changed

9 files changed

+4038
-4048
lines changed

src/Async.ml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,10 @@ let pp_sock_info = function
127127
| Pipe -> "Pipe"
128128
| Lock -> "Lock"
129129

130-
exception SockError of socket_type * exn
131-
132130
let printexn e =
133131
match e with
134-
| SockError (_, e) -> Printf.sprintf "SockError(%s)" (Printexc.to_string e)
135132
| e -> (Printexc.to_string e)
136133

137-
let clientError exn = raise (SockError(Client,exn))
138-
let ioError exn = raise(SockError(Io,exn))
139-
140134
type pending_status =
141135
NoEvent | Wait : 'a pending -> pending_status | TooSoon of bool
142136

@@ -359,7 +353,6 @@ let rec read c s o l =
359353
with Unix.(Unix_error((EAGAIN|EWOULDBLOCK),_,_))
360354
| Ssl.(Read_error(Error_want_read|Error_want_write
361355
|Error_want_connect|Error_want_accept|Error_zero_return)) -> perform_read c s o l
362-
| exn -> clientError exn
363356

364357
and perform_read c s o l =
365358
perform (Io {sock = c.sock; fn = (fun () -> read c s o l) })
@@ -371,7 +364,6 @@ let rec write c s o l =
371364
| Ssl.(Write_error(Error_want_read|Error_want_write
372365
|Error_want_connect|Error_want_accept|Error_zero_return)) ->
373366
perform_write c s o l
374-
| exn -> clientError exn
375367

376368
and perform_write c s o l =
377369
perform (Io {sock = c.sock; fn = (fun () -> write c s o l) })
@@ -391,7 +383,6 @@ let rec sendfile c fd o l =
391383
| Ssl.(Write_error(Error_want_read|Error_want_write
392384
|Error_want_connect|Error_want_accept|Error_zero_return)) ->
393385
perform_sendfile c fd o l
394-
| exn -> clientError exn
395386

396387
and perform_sendfile c fd o l =
397388
perform (Io {sock = c.sock; fn = (fun () -> sendfile c fd o l) })
@@ -444,15 +435,13 @@ module Io = struct
444435
with Unix.(Unix_error((EAGAIN|EWOULDBLOCK),_,_)) ->
445436
register io;
446437
schedule_io io.sock (fun () -> read io s o l)
447-
| exn -> ioError exn
448438

449439
let rec write (io:t) s o l =
450440
try
451441
Util.single_write io.sock s o l
452442
with Unix.(Unix_error((EAGAIN|EWOULDBLOCK),_,_)) ->
453443
register io;
454444
schedule_io io.sock (fun () -> write io s o l)
455-
| exn -> ioError exn
456445

457446
end
458447

@@ -857,7 +846,7 @@ let accept_loop status listens pipes maxc =
857846
with
858847
| Unix.Unix_error((EAGAIN|EWOULDBLOCK),_,_) -> ()
859848
| exn ->
860-
(** normal if client close connection brutally? *)
849+
(* normal if client close connection brutally? *)
861850
Log.f (Exc 1) (fun k -> k "Exception during epoll_wait: %s" (printexn exn))
862851
done
863852

src/Async.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ type socket_type =
113113

114114
exception NoRead
115115
exception NoWrite
116-
exception SockError of socket_type * exn
117116
exception ClosedByHandler
118117
exception TimeOut
119118

src/Server.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ let handle_client_ (self:t) (client:Async.client) : unit =
233233
log (Req 0) (fun k -> k "response sent after %fms" (1e3 *. (Unix.gettimeofday () -. req.start_time)));
234234
if !cont then Async.yield ()
235235
with
236-
| Sys_error _ | Unix.Unix_error _ | Async.ClosedByHandler | Async.TimeOut as e ->
237-
log (Exc 1) (fun k -> k "broken connection (%s)"
238-
(Async.printexn e));
239-
cont := false; (* connection broken somehow *)
240-
241236
| Headers.Bad_req (c,s,headers,cookies) ->
242237
log (Req 0) (fun k -> k "not 200 status: %d (%s)" (c :> int) s);
243238
let res = Response.make_raw ~headers ~cookies ~code:c s in
@@ -247,6 +242,13 @@ let handle_client_ (self:t) (client:Async.client) : unit =
247242
end;
248243
if not ((c :> int) < 500) then cont := false else Async.yield ()
249244

245+
| Sys_error _ | Unix.Unix_error _
246+
| Ssl.Write_error _ | Ssl.Read_error _
247+
| Async.ClosedByHandler | Async.TimeOut as e ->
248+
log (Exc 1) (fun k -> k "probably broken connection (%s)"
249+
(Async.printexn e));
250+
cont := false; (* connection broken somehow *)
251+
250252
| e ->
251253
log (Exc 0) (fun k -> k "internal server error (%s)"
252254
(Async.printexn e));

src/Session.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
type t
2-
type session_data = Async.session_data = ..
2+
type session_data = ..
33
type session_data += NoData
44

55
(** Managment of sessions using cookies *)

tests/bench.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ let measure server cmd values =
2626
let s = match server with
2727
| Some server ->
2828
let args = Array.of_list (String.split_on_char ' ' server) in
29-
let chs = Unix.open_process_args args.(0) args in
30-
let pid = Unix.process_pid chs in
29+
let chs = Unix.open_process_args_out args.(0) args in
30+
let pid = Unix.process_out_pid chs in
3131
Unix.sleep 1;
3232
Some(chs,pid)
3333
| None -> None
@@ -48,9 +48,9 @@ let measure server cmd values =
4848
in
4949
let res = List.map fn values in
5050
(match s with
51-
| Some((ch,ch'),pid) ->
51+
| Some(ch,pid) ->
5252
Unix.kill pid Sys.sigkill;
53-
close_in ch; close_out ch'
53+
close_out ch
5454
| None -> ());
5555
res
5656

@@ -103,7 +103,7 @@ let _ = csv := add_column !csv "nbc" string_of_int (List.map snd values)
103103
let data =
104104
Printf.printf "serve_files\n%!";
105105
measure
106-
(Some "../_build/default/tests/serve_files.exe --log-requests 0 --dir /var/www/nginx -c 2100 --timeout 10")
106+
(Some "../_build/default/tests/serve_files.exe --log-requests 0 --dir /var/www/nginx -c 2100 --timeout 10")
107107
(fun ((file, d), c) ->
108108
Printf.sprintf "wrk -t5 -c%d --timeout 10 -d%d http://localhost:9080/%s"
109109
c d file)
@@ -114,7 +114,7 @@ let _ = csv := add_column !csv "sh\\\\_cc" string_of_float data
114114
let data =
115115
Printf.printf "measure http_of_dir\n%!";
116116
measure
117-
(Some "../_build/default/src/bin/http_of_dir.exe --log-requests 0 -c 2100 --port=8080 --timeout 10 /var/www/nginx")
117+
(Some "../_build/default/src/bin/http_of_dir.exe --log-requests 0 -c 2100 --port=8080 --timeout 10 /var/www/nginx")
118118
(fun ((file, d), c) ->
119119
Printf.sprintf "wrk -t5 -c%d --timeout 10 -d%d http://localhost:8080/%s"
120120
c d file)
@@ -125,7 +125,7 @@ let _ = csv := add_column !csv "sh\\\\_dir" string_of_float data
125125
let data =
126126
Printf.printf "measure http_of_dir\n%!";
127127
measure
128-
(Some "../_build/default/src/bin/http_of_dir.exe --log-requests 0 --ssl ../_build/default/tests/domain.crt ../_build/default/tests/domain.key -c 2100 --port=8443 --timeout 10 /var/www/nginx")
128+
(Some "../_build/default/src/bin/http_of_dir.exe --log-requests 0 --ssl ../_build/default/tests/domain.crt ../_build/default/tests/domain.key -c 2100 --port=8443 --timeout 10 /var/www/nginx")
129129
(fun ((file, d), c) ->
130130
Printf.sprintf "wrk -t5 -c%d --timeout 10 -d%d https://localhost:8443/%s"
131131
c d file)

0 commit comments

Comments
 (0)