mldonkey-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...


From: mldonkey-commits
Subject: [Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...
Date: Sun, 22 Apr 2007 22:31:53 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       07/04/22 22:31:53

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonComplexOptions.ml commonOptions.ml 
        src/utils/lib  : unix32.ml unix32.mli 

Log message:
        patch #5855

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.1240&r2=1.1241
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonComplexOptions.ml?cvsroot=mldonkey&r1=1.73&r2=1.74
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonOptions.ml?cvsroot=mldonkey&r1=1.205&r2=1.206
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/utils/lib/unix32.ml?cvsroot=mldonkey&r1=1.68&r2=1.69
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/utils/lib/unix32.mli?cvsroot=mldonkey&r1=1.24&r2=1.25

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.1240
retrieving revision 1.1241
diff -u -b -r1.1240 -r1.1241
--- distrib/ChangeLog   20 Apr 2007 22:55:08 -0000      1.1240
+++ distrib/ChangeLog   22 Apr 2007 22:31:53 -0000      1.1241
@@ -14,6 +14,10 @@
 ChangeLog
 =========
 
+2007/04/23
+5855: Increase Unix32.max_cache_size, fix max_opened_connections check
+      (thx to pango)
+
 2007/04/21
 5878: HTML: Fix preview in vd <num> broken by patch #5866
 

Index: src/daemon/common/commonComplexOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonComplexOptions.ml,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -b -r1.73 -r1.74
--- src/daemon/common/commonComplexOptions.ml   1 Apr 2007 13:05:05 -0000       
1.73
+++ src/daemon/common/commonComplexOptions.ml   22 Apr 2007 22:31:53 -0000      
1.74
@@ -1211,63 +1211,77 @@
   option_hook max_filenames (fun _ ->
     shorten_all_file_filenames !!max_filenames
   );
+
+  let max_opened_connections_pass = ref 0 in
   option_hook max_opened_connections (fun _ ->
+
+  incr max_opened_connections_pass;
+
+(* let users see if the option is called again *)
+  let lprintf_nl s = lprintf_nl2
+      (Printf.sprintf "%s pass %d:" log_prefix !max_opened_connections_pass) s 
in
+
   if !verbose then lprintf_nl
     "checking max_opened_connections = %d for validity" 
!!max_opened_connections;
-(* original code from ./src/config/unix/MlUnix.ml
-let max_all_sockets = getdtablesize ()
-let max_sockets = max (max_all_sockets - 100) (max_all_sockets / 2)
-let max_filedescs = (max_all_sockets - max_sockets) / 2 *)
-
-  (* ulimit open files. minimum 150, most systems have 1024 *)
-  let max_all_sockets = Unix2.c_getdtablesize () in
-
-  (* old max_sockets code: max (150 - 100) (150 / 2),
-     minimum number of max_opened_connections *)
-  let min_conns = 75 in
 
-  if min_conns > !!max_opened_connections then begin
+(* maximum value of open sockets/files allowed *)
+  let max_all_fds = Unix2.c_getdtablesize () in
+
+(* ini files, dynamic libs, etc. *)
+  let reserved_fds = max CommonOptions.min_reserved_fds (max_all_fds / 50) in
+
+(* minimum number of max_opened_connections, p2p needs some sockets *)
+  let min_conns = CommonOptions.min_connections in
+(* max_conns *should* be greater than min_conns at that point, because of
+   the sanity check at start time in CommonOptions;
+   taking the max is just a safety belt from a paranoid :) *)
+  let max_conns = max min_conns
+    (max_all_fds - reserved_fds - Unix32.max_cache_size_default) in
+
+  let print_stats verbose =
+    if verbose then begin
+      lprintf_nl "file descriptors status: total allowed (ulimit -n) %d" 
max_all_fds;
+      lprintf_nl "- max_opened_connections %d (%d%% indirect)"
+        !!max_opened_connections !!max_indirect_connections;
+      lprintf_nl "- file cache size %d" (Unix32.get_max_cache_size ());
+      lprintf_nl "- reserved %d" reserved_fds;
+      let s,v =
+        let v1 =
+          max_all_fds - !!max_opened_connections - (Unix32.get_max_cache_size 
()) - reserved_fds
+        in
+        if v1 >= 0 then "left", v1 else "missing", (abs v1)
+      in
+      lprintf_nl "= %d descriptors %s" v s
+    end
+  in
+
+  if !!max_opened_connections < min_conns then begin
     lprintf_nl "max_opened_connections is set too low (%d), raising to %d"
       !!max_opened_connections min_conns;
+    print_stats true;
     max_opened_connections =:= min_conns
-  end;
+  end
+  else if !!max_opened_connections > max_conns then begin
+    lprintf_nl "max_opened_connections is set too high (%d), lowering to %d"
+      !!max_opened_connections max_conns;
+    print_stats true;
+    max_opened_connections =:= max_conns
+  end
+  else begin
+    TcpBufferedSocket.set_max_opened_connections (fun _ -> 
!!max_opened_connections);
 
-  let reserved_fds = 40 in (* ini files, dynamic libs, etc. *)
+    let unused_fds = max_conns - !!max_opened_connections in
 
-  let total_files = (* maximum number of files in use at the same time *)
-    (max (List.length !!files) !!max_concurrent_downloads) + 
!!max_upload_slots + reserved_fds
-  in
+    Unix32.set_max_cache_size
+      (Unix32.max_cache_size_default + unused_fds * 75 / 100);
 
-  let wanted_socks = !!max_opened_connections + total_files in
+    calc_real_max_indirect_connections ();
 
-  if max_all_sockets < wanted_socks then
-    if max_all_sockets < total_files + min_conns then (* check if ulimit is 
enough to allow total_files + min_conns *)
-      begin
-        lprintf_nl "only %d file descriptors available, raise ulimit open 
files to at least %d"
-          max_all_sockets wanted_socks;
-        lprintf_nl "FD info: max_opened_connections %d, number of (possible) 
concurrent downloads %d, = %d fd needed"
-          !!max_opened_connections total_files wanted_socks;
-        CommonGlobals.exit_properly 71
-      end
-  else
-    begin
-      let new_max_opened_connections =
-        max (max_all_sockets - total_files) (max_all_sockets / 2)
-      in
-      lprintf_nl "max_opened_connections is set too high (%d), reducing to %d"
-        !!max_opened_connections new_max_opened_connections;
-      max_opened_connections =:= new_max_opened_connections;
+    print_stats !verbose
     end;
 
-  if !verbose then lprintf_nl
-    "max_opened_connections %d, total_files %d, max_concurrent_downloads %d, 
!!files %d"
-      !!max_opened_connections total_files !!max_concurrent_downloads 
(List.length !!files);
-
-  TcpBufferedSocket.set_max_opened_connections
-    (fun _ -> !!max_opened_connections);
-
-  Unix32.max_cache_size := total_files - reserved_fds;
-  calc_real_max_indirect_connections ()
+  if !verbose then lprintf_nl "checking max_opened_connections finished";
+  decr max_opened_connections_pass
 )
 
 let _ =

Index: src/daemon/common/commonOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonOptions.ml,v
retrieving revision 1.205
retrieving revision 1.206
diff -u -b -r1.205 -r1.206
--- src/daemon/common/commonOptions.ml  8 Apr 2007 14:59:29 -0000       1.205
+++ src/daemon/common/commonOptions.ml  22 Apr 2007 22:31:53 -0000      1.206
@@ -127,6 +127,9 @@
   lprintf_nl "waiting %d seconds to exit..." seconds;
   Unix.sleep seconds
 
+let min_reserved_fds = 50
+let min_connections = 50
+
 let _ =
   lprintf_nl "Starting MLDonkey %s ... " Autoconf.current_version;
   let ulof_old = Unix2.c_getdtablesize () in
@@ -139,8 +142,10 @@
   let ulof = Unix2.c_getdtablesize () in
   if ulof_old <> ulof then
     lprintf_nl "raised ulimit for open files from %d to %d" ulof_old ulof;
-  if ulof < 150 then begin
-    lprintf_nl "ulimit for open files is set to %d, at least 150 is required, 
exiting..." ulof;
+  let absolute_min = Unix32.max_cache_size_default +
+    min_reserved_fds + min_connections in
+  if ulof < absolute_min then begin
+    lprintf_nl "ulimit for open files is set to %d, at least %d is required, 
exiting..." ulof absolute_min;
     exit 2
   end;
 

Index: src/utils/lib/unix32.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/lib/unix32.ml,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- src/utils/lib/unix32.ml     11 Feb 2007 13:07:48 -0000      1.68
+++ src/utils/lib/unix32.ml     22 Apr 2007 22:31:53 -0000      1.69
@@ -34,7 +34,8 @@
 let create_file_mode = ref 0o664
 let create_dir_mode = ref 0o755
 let verbose = ref false
-let max_cache_size = ref 50
+let max_cache_size_default = 50
+let max_cache_size = ref max_cache_size_default
   
 let mini (x: int) (y: int) =
   if x > y then y else x
@@ -1836,6 +1837,12 @@
             Printf.sprintf "unknown (%Ld)" s.f_type
   with e -> "not supported"
 
+let set_max_cache_size v =
+  max_cache_size := v;
+  while !FDCache.cache_size > !max_cache_size do FDCache.close_one () done
+
+let get_max_cache_size () = !max_cache_size
+
 let _ =
   Heap.add_memstat "Unix32" (fun level buf ->
       let counter = ref 0 in

Index: src/utils/lib/unix32.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/utils/lib/unix32.mli,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- src/utils/lib/unix32.mli    28 Nov 2006 23:52:18 -0000      1.24
+++ src/utils/lib/unix32.mli    22 Apr 2007 22:31:53 -0000      1.25
@@ -21,6 +21,10 @@
 
 val verbose : bool ref
 
+val get_max_cache_size : unit -> int
+val set_max_cache_size : int -> unit
+val max_cache_size_default : int
+
 val external_start : unit -> unit
 val external_exit : unit -> unit
 val uname : unit -> string
@@ -42,7 +46,6 @@
 val fds_size : int
 val filename : t -> string
 val rename : t -> string -> unit 
-val max_cache_size : int ref
 val mtime : string -> float
 val mtime64 : t -> float
 val owner : string -> (string * string)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]