From aff304f6ae6592908e05c95ee13146d2cf143df9 Mon Sep 17 00:00:00 2001 From: Cedric RICARD Date: Wed, 5 Dec 2007 22:25:09 +0000 Subject: [PATCH] small optimization on reading HTTP headers --- calexium_lib/web/CXM_multihost_http_server.anubis | 80 ++++++++++++++++++++++++++++++++++++++------------------------------------------ 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/calexium_lib/web/CXM_multihost_http_server.anubis b/calexium_lib/web/CXM_multihost_http_server.anubis index d88ecfb..5f997fa 100644 --- a/calexium_lib/web/CXM_multihost_http_server.anubis +++ b/calexium_lib/web/CXM_multihost_http_server.anubis @@ -733,13 +733,13 @@ define String "[" + virtual_machine_id + "] ". define ReadResult - read + read_from_connexion ( BufferedConnection connection, Int32 size, Int32 time_out ) = - //println(pid + "read(" + size + ")"); + //println(pid + "read_from_connexion(" + size + ")"); if *connection.read_pos < length(*connection.buffer) then //println(pid + " reading from buffer (size = " + length(*connection.buffer) + ", pos = " + *connection.read_pos); @@ -751,7 +751,7 @@ define ReadResult if size > size_read then //println("Wanted " + size + ", read only " + size_read); - if read(connection, size - size_read, time_out) is + if read_from_connexion(connection, size - size_read, time_out) is { error then error, timeout then ok(result), @@ -769,41 +769,9 @@ define ReadResult connection.buffer <- ba; connection.read_pos <- 0; //println(pid + "rb = " + length(*read_buffer)); - read(connection, size, time_out) + read_from_connexion(connection, size, time_out) }. - -define Result(Error,Word8) - read_one_byte - ( - BufferedConnection connection, - Int32 dead_line, - DenialOfService dos - ) = - //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else - if nth(*connection.read_pos, *connection.buffer) is - { - failure then - if read(connection,1,600) is // the connection is closed after 10 minutes of inactivity - { - error then error(cannot_read_from_connection), - timeout then error(timeout(600)), - //record_dubious_connection(connection,dead_line,dos), - ok(ba) then if nth(0,ba) is - { - failure then error(cannot_read_from_connection), - success(c) then - // println("-" + pid + "read [" + implode([c]) + "]\t"); - ok(c) - } - }, - success(c) then - connection.read_pos <- *connection.read_pos + 1; - ok(c) - }. - - - define Result(Error,Word8) next_char // reading a character (check the list first, and read on the connection // only when the list is empty). @@ -812,10 +780,38 @@ define Result(Error,Word8) Int32 dead_line, DenialOfService dos ) = - with t2_tmp = (UTime) now, + //with t2_tmp = (UTime) now, if *unput_chars is { - [ ] then with ret = read_one_byte(connection,dead_line,dos), accumulate_t2(t2_tmp); ret, + [ ] then + // /////////////////// + // Buffered reading + //if now > dead_line then record_dubious_connection(connection,dead_line,dos) else + if nth(*connection.read_pos, *connection.buffer) is + { + failure then + if read_from_connexion(connection,1,600) is // the connection is closed after 10 minutes of inactivity + { + error then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection), + timeout then /*accumulate_t2(t2_tmp);*/ error(timeout(600)), + //record_dubious_connection(connection,dead_line,dos), + ok(ba) then if nth(0,ba) is + { + failure then /*accumulate_t2(t2_tmp);*/ error(cannot_read_from_connection), + success(c) then + //println("-" + pid + "read [" + implode([c]) + "]\t"); + //accumulate_t2(t2_tmp); + ok(c) + } + }, + success(c) then + connection.read_pos <- *connection.read_pos + 1; + //accumulate_t2(t2_tmp); + ok(c) + }, + + // /////////////////// + // standard reading // if read(connection.conn, 1, 600) is // the connection is closed after 10 minutes of inactivity // { // error then accumulate_t2(t2_tmp); println(pid + "read failed)"); error(cannot_read_from_connection), @@ -829,7 +825,7 @@ define Result(Error,Word8) // }, [h . t] then - unput_chars <- t; accumulate_t2(t2_tmp); + unput_chars <- t; //accumulate_t2(t2_tmp); ok(h) }. @@ -1722,7 +1718,7 @@ define Result(Error,ByteArray) ) = if body_size = 0 then ok(constant_byte_array(0,0)) else if retries =< 0 then error(cannot_read_from_connection) else - if read(connection,body_size,60) is + if read_from_connexion(connection,body_size,60) is { error then error(cannot_read_from_connection), timeout then error(timeout(60)), @@ -3002,9 +2998,9 @@ define One send_answer(host_name, desc,connection.conn, request_line, headers, body, make_generate_trust_ticket(dos)); with duration = (UTime) now - *t0, - println("Request duration: " + utime_to_string(duration)); + println("Request duration: " + utime_to_string(duration)) //println("BufferRead duration: " + utime_to_string(*t1)); - println("next_char duration: " + utime_to_string(*t2)) + //println("next_char duration: " + utime_to_string(*t2)) } } } -- libgit2 0.21.4