[Top][All Lists]
[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, 03 Dec 2006 20:47:12 +0000 |
CVSROOT: /sources/mldonkey
Module name: mldonkey
Changes by: spiralvoice <spiralvoice> 06/12/03 20:47:12
Modified files:
distrib : ChangeLog
src/daemon/common: commonSources.ml commonSources.mli
Log message:
patch #5610
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.1126&r2=1.1127
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonSources.ml?cvsroot=mldonkey&r1=1.40&r2=1.41
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonSources.mli?cvsroot=mldonkey&r1=1.10&r2=1.11
Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.1126
retrieving revision 1.1127
diff -u -b -r1.1126 -r1.1127
--- distrib/ChangeLog 2 Dec 2006 16:01:13 -0000 1.1126
+++ distrib/ChangeLog 3 Dec 2006 20:47:11 -0000 1.1127
@@ -14,6 +14,9 @@
ChangeLog
=========
+2006/12/03
+5610: CommonSources: Cleanups and reformatting the code (pango)
+
2006/12/02
5608: Multiuser, chgrp: Prevent change of file_group to None
if the user is not file_owner
Index: src/daemon/common/commonSources.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonSources.ml,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- src/daemon/common/commonSources.ml 28 Nov 2006 23:58:02 -0000 1.40
+++ src/daemon/common/commonSources.ml 3 Dec 2006 20:47:12 -0000 1.41
@@ -110,14 +110,14 @@
"connected_sources";
"connecting_sources";
"busy_sources";
- |]
+|]
let nqueues = Array.length queue_name
let queue_period = Array.create nqueues 600
-let _ =
+let () =
queue_period.(new_sources_queue) <- 0;
queue_period.(connected_sources_queue) <- 0;
queue_period.(connecting_sources_queue) <- 0;
@@ -239,14 +239,12 @@
module HS = Weak.Make(struct
type t = source
let hash s = Hashtbl.hash s.source_uid
-
let equal x y = x.source_uid = y.source_uid
end)
module H = Weak.Make(struct
type t = source
let hash s = Hashtbl.hash s.source_num
-
let equal x y = x.source_num = y.source_num
end)
@@ -291,7 +289,6 @@
function_add_location = not_implemented "function_add_location";
function_remove_location = not_implemented
"function_remove_location";
-
}
let indirect_connections = ref 0
@@ -334,13 +331,13 @@
(* *)
(*************************************************************************)
-let rec find_throttled_queue queue =
+ let rec find_throttled_queue queue =
if queue_period.(queue) > 0 || queue = old_sources3_queue then
queue
else
find_throttled_queue (queue + 1)
-let get_throttle_delay m q throttled =
+ let get_throttle_delay m q throttled =
if throttled then
(max 0
(queue_period.(q)
@@ -357,49 +354,45 @@
But that function really needs to be fast.
Also, this works because Queues are based on Sets, and that Set.iter
gives elements in increasing keys order *)
-exception BreakOutOfLoop
+ exception BreakOutOfLoop
-let count_file_ready_sources m q throttled =
+ let count_file_ready_sources m q throttled =
let ready_count = ref 0 in
let throttle_delay = get_throttle_delay m q throttled in
- let ready_threshold = last_time () - !!min_reask_delay - throttle_delay in
+ let ready_threshold =
+ last_time () - !!min_reask_delay - throttle_delay in
(try
Queue.iter
- (fun ( time, s ) ->
- if time >= ready_threshold then
- raise BreakOutOfLoop;
+ (fun (time, s) ->
+ if time >= ready_threshold then raise BreakOutOfLoop;
incr ready_count
- ) m.manager_sources.( q )
+ ) m.manager_sources.(q)
with BreakOutOfLoop -> ());
!ready_count
(*
* determine the total number of ready sources for all downloading files per
queue
*)
-let count_ready_sources queue throttled =
- let ready_count = ref 0 in
- List.iter
- (fun m ->
+ let count_ready_sources queue throttled =
+ List.fold_left (fun ready_count m ->
let f = m.manager_file () in
if file_state f = FileDownloading then
- ready_count := !ready_count + count_file_ready_sources m queue
throttled
- ) !file_sources_managers;
- !ready_count
+ ready_count + count_file_ready_sources m queue throttled
+ else ready_count
+ ) 0 !file_sources_managers
-let rec find_max_overloaded q managers =
- let current_max = ref (-1) in
- let remaining_managers = ref [] in
- List.iter
- (fun m ->
+ let rec find_max_overloaded q managers =
+ let _, remaining_managers =
+ List.fold_left (fun ((current_max, remaining_managers) as acc) m ->
let ready_sources = count_file_ready_sources m q true in
- if ready_sources > !current_max then begin
- current_max := ready_sources;
- remaining_managers := [m]
- end else if ready_sources = !current_max then
- remaining_managers := m :: !remaining_managers
- ) managers;
- !remaining_managers
+ if ready_sources > current_max then
+ (ready_sources, [m])
+ else if ready_sources = current_max then
+ (current_max, m :: remaining_managers)
+ else acc
+ ) (-1, []) managers in
+ remaining_managers
(*************************************************************************)
@@ -416,7 +409,8 @@
if s.source_last_attempt <> 0 then
Printf.bprintf buf " last_attemps: %d" s.source_last_attempt;
List.iter (fun r ->
- Printf.bprintf buf " File %s\n" (file_best_name
(r.request_file.manager_file ()));
+ Printf.bprintf buf " File %s\n"
+ (file_best_name (r.request_file.manager_file ()));
Printf.bprintf buf " Score: %d\n" r.request_score;
if r.request_time <> 0 then
Printf.bprintf buf " Time: %d\n" r.request_time;
@@ -430,15 +424,16 @@
*)
let need_new_sources file =
+ let ready_threshold = last_time () - !!min_reask_delay in
let ready_count = ref 0 in
for i = good_sources_queue to old_sources1_queue do
- let lookin = file.manager_sources.( i ) in
- let ready_threshold = last_time () - !!min_reask_delay in
- Queue.iter
- (fun (time, s) ->
- if time < ready_threshold then
+ let lookin = file.manager_sources.(i) in
+ try
+ Queue.iter (fun (time, s) ->
+ if time >= ready_threshold then raise BreakOutOfLoop;
incr ready_count
) lookin
+ with BreakOutOfLoop -> ()
done;
(* let work_count = !ready_count +
(Queue.length ( file.manager_sources.( new_sources_queue ) )) +
@@ -467,24 +462,22 @@
let print buf output_type =
let pos_to_string v =
- (if v > 0 then string_of_int(v) else "-")
- in
+ if v > 0 then string_of_int v else "-" in
- html_mods_cntr_init();
+ html_mods_cntr_init ();
let mycntr = ref 1 in
- let html_tr () = begin
- mycntr := html_mods_cntr();
- Printf.bprintf buf "\\<tr class=\\\"dl-%d\\\"\\>" (!mycntr)
- end
- in
- let html_tr_same () = Printf.bprintf buf "\\<tr
class=\\\"dl-%d\\\"\\>" (!mycntr) in
+ let html_tr () =
+ mycntr := html_mods_cntr ();
+ Printf.bprintf buf "\\<tr class=\\\"dl-%d\\\"\\>" !mycntr in
+
+ let html_tr_same () =
+ Printf.bprintf buf "\\<tr class=\\\"dl-%d\\\"\\>" !mycntr in
(* Header *)
if output_type = HTML then
- begin
-
- let header = Printf.sprintf "File sources per manager queue (%d)"
(List.length !file_sources_managers) in
+ let header = Printf.sprintf "File sources per manager queue (%d)"
+ (List.length !file_sources_managers) in
Printf.bprintf buf "\\<div class=results\\>";
html_mods_table_header buf "sourcesTable" "sources" [];
@@ -496,30 +489,42 @@
Printf.bprintf buf "\\</tr\\>\\</table\\>\\</div\\>\n";
html_mods_table_header buf "sourcesTable" "sources" [
- ( "0", "srh br", "New sources", Printf.sprintf "New(%d)"
new_sources_queue );
- ( "0", "srh br", "Good sources", Printf.sprintf "Good(%d)"
good_sources_queue );
- ( "0", "srh br", "Ready saved sources", Printf.sprintf
"Ready(%d)" ready_saved_sources_queue);
- ( "0", "srh br", "Waiting saved sources", Printf.sprintf
"Wait(%d)" waiting_saved_sources_queue);
- ( "0", "srh br", "Old sources 1", Printf.sprintf "Old1(%d)"
old_sources1_queue );
- ( "0", "srh br", "Old sources 2", Printf.sprintf "Old2(%d)"
old_sources2_queue );
- ( "0", "srh br", "Old sources 3", Printf.sprintf "Old3(%d)"
old_sources3_queue );
- ( "0", "srh br", "Do not try sources", Printf.sprintf "nTry(%d)"
do_not_try_queue );
- ( "0", "srh br", "Connected sources", Printf.sprintf "Conn(%d)"
connected_sources_queue );
- ( "0", "srh br", "Connecting sources", Printf.sprintf "Cing(%d)"
connecting_sources_queue );
- ( "0", "srh br", "Busy sources", Printf.sprintf "Busy(%d)"
busy_sources_queue );
+ ( "0", "srh br", "New sources",
+ Printf.sprintf "New(%d)" new_sources_queue );
+ ( "0", "srh br", "Good sources",
+ Printf.sprintf "Good(%d)" good_sources_queue );
+ ( "0", "srh br", "Ready saved sources",
+ Printf.sprintf "Ready(%d)" ready_saved_sources_queue);
+ ( "0", "srh br", "Waiting saved sources",
+ Printf.sprintf "Wait(%d)" waiting_saved_sources_queue);
+ ( "0", "srh br", "Old sources 1",
+ Printf.sprintf "Old1(%d)" old_sources1_queue );
+ ( "0", "srh br", "Old sources 2",
+ Printf.sprintf "Old2(%d)" old_sources2_queue );
+ ( "0", "srh br", "Old sources 3",
+ Printf.sprintf "Old3(%d)" old_sources3_queue );
+ ( "0", "srh br", "Do not try sources",
+ Printf.sprintf "nTry(%d)" do_not_try_queue );
+ ( "0", "srh br", "Connected sources",
+ Printf.sprintf "Conn(%d)" connected_sources_queue );
+ ( "0", "srh br", "Connecting sources",
+ Printf.sprintf "Cing(%d)" connecting_sources_queue );
+ ( "0", "srh br", "Busy sources",
+ Printf.sprintf "Busy(%d)" busy_sources_queue );
( "0", "srh br", "Total sources", "All" );
( "0", "srh br", "Filename", "Name" ); ];
- end
- else
- begin
+ else begin
Printf.bprintf buf "Statistics on sources: time %d\n" (last_time
());
- Printf.bprintf buf "File sources per manager queue(%d):\n"
(List.length !file_sources_managers);
+ Printf.bprintf buf "File sources per manager queue(%d):\n"
+ (List.length !file_sources_managers);
Printf.bprintf buf "new good redy wait old1 old2 old3 ntry conn
cing busy all\n";
(* "9999 9999 9999 9999 9999 9999 9999 9999 9999 9999
9999 9999"
11*5 chars
- one row each: all,indirect,ready*)
+ one row each: all,indirect,ready *)
end;
+ let list_sum = List.fold_left (+) 0 in
+
let nsources_per_queue = Array.create nqueues 0 in
let nready_per_queue = Array.create nqueues 0 in
let nindirect_per_queue = Array.create nqueues 0 in
@@ -527,201 +532,163 @@
let nall = ref 0 in
let naact = ref 0 in
let naneed = ref 0 in
+ let downloading_managers =
+ List.filter (fun m ->
+ file_state (m.manager_file ()) = FileDownloading
+ ) !file_sources_managers in
let my_file_sources_managers =
- List.sort
- (fun f1 f2 ->
+ List.sort (fun f1 f2 ->
let best_name1 = file_best_name (f1.manager_file ()) in
let best_name2 = file_best_name (f2.manager_file ()) in
String.compare best_name1 best_name2
- ) (List.filter (fun m -> file_state (m.manager_file ()) =
FileDownloading) !file_sources_managers)
- in
+ ) downloading_managers in
(* Files *)
+ let ready_threshold = last_time () - !!min_reask_delay in
List.iter (fun m ->
let name = file_best_name (m.manager_file ()) in
- if m.manager_all_sources <> 0 then
- begin
- let anready = ref 0 in
- let antready = ref 0 in
- let anindirect = ref 0 in
- let aninvalid = ref 0 in
+ let need_sources = need_new_sources m in
+ if need_sources then incr naneed;
+
+ if m.manager_all_sources <> 0 then begin
let slist = ref [] in
let sreadylist = ref [] in
let streadylist = ref [] in
let sindirectlist = ref [] in
let sinvalidlist = ref [] in
- let sready = ref "" in
- let stready = ref "" in
- let sindirect = ref "" in
- let sinvalid = ref "" in
(* Queues *)
- for i = 0 to nqueues -1 do
- let q = m.manager_sources.(i) in
- if output_type = HTML then
- slist := !slist @ [
- ("", "sr ar br", (pos_to_string (Queue.length q))); ]
- else
- Printf.bprintf buf "%4d " (Queue.length q);
-
+ Array.iteri (fun i q ->
let nready = ref 0 in
+ let ntready = count_file_ready_sources m i true in
let nindirect = ref 0 in
let ninvalid = ref 0 in
let nsources = ref 0 in
- let ready_threshold = last_time () - !!min_reask_delay in
(* Sources *)
Queue.iter (fun (time, s) ->
incr nsources;
- if M.indirect_source s.source_uid then
- incr nindirect
- else if not (M.direct_source s.source_uid) then
- incr ninvalid;
- if time < ready_threshold then
- incr nready
- else if i = new_sources_queue then
- begin
+ if M.indirect_source s.source_uid then incr nindirect
+ else if not (M.direct_source s.source_uid) then incr ninvalid;
+ if time < ready_threshold then incr nready
+ else if i = new_sources_queue then begin
Printf.bprintf buf "ERROR: Source is not ready in
new_sources_queue !\n";
print_source buf s
end
) q;
- if output_type = HTML then
- begin
- sreadylist := !sreadylist @ [
- ("", "sr ar br", (pos_to_string (Queue.length q))); ] ;
- streadylist := !streadylist @ [
- ("", "sr ar br", (pos_to_string
(count_file_ready_sources m i true))); ] ;
- sindirectlist := !sindirectlist @ [
- ("", "sr ar br", (pos_to_string !nindirect)); ] ;
- sinvalidlist := !sinvalidlist @ [
- ("", "sr ar br", (pos_to_string !ninvalid)); ] ;
- end
- else
- begin
- sready := Printf.sprintf "%s%4d " !sready !nready;
- stready := Printf.sprintf "%s%4d " !stready
(count_file_ready_sources m i true);
- sindirect := Printf.sprintf "%s%4d " !sindirect
!nindirect;
- sinvalid := Printf.sprintf "%s%4d " !sinvalid !ninvalid
- end;
+ slist := Queue.length q :: !slist;
+ sreadylist := !nready :: !sreadylist;
+ streadylist := ntready :: !streadylist;
+ sindirectlist := !nindirect :: !sindirectlist;
+ sinvalidlist := !ninvalid :: !sinvalidlist;
- anready := !anready + !nready;
- antready := !antready + (count_file_ready_sources m i true);
- anindirect := !anindirect + !nindirect;
- aninvalid := !aninvalid + !ninvalid;
nready_per_queue.(i) <- nready_per_queue.(i) + !nready;
nindirect_per_queue.(i) <- nindirect_per_queue.(i) +
!nindirect;
ninvalid_per_queue.(i) <- ninvalid_per_queue.(i) + !ninvalid;
nsources_per_queue.(i) <- nsources_per_queue.(i) + !nsources;
+ ) m.manager_sources; (* end Queues *)
- done; (* end Queues *)
+ let slist = List.rev !slist in
+ let sreadylist = List.rev !sreadylist in
+ let streadylist = List.rev !streadylist in
+ let sindirectlist = List.rev !sindirectlist in
+ let sinvalidlist = List.rev !sinvalidlist in
- if output_type = HTML then
- begin
+ if output_type = HTML then begin
html_tr ();
html_mods_td buf (
- !slist
- @ [ ("", "sr ar br", Printf.sprintf "%d"
m.manager_all_sources); ]
- @ [ ("Filename", "sr", (shorten name !!max_name_len)); ]
);
+ (List.map (fun qlength ->
+ ("", "sr ar br", pos_to_string qlength)) slist) @
+ [ ("", "sr ar br", string_of_int m.manager_all_sources);
+ ("Filename", "sr", shorten name !!max_name_len); ] );
Printf.bprintf buf "\\</tr\\>\n";
html_tr_same ();
html_mods_td buf (
- !sreadylist
- @ [ ("", "sr ar br", Printf.sprintf "%d" !anready); ]
- @ [ ("", "sr", ((Printf.sprintf "ready with %d active"
m.manager_active_sources)
- ^ (if file_state (m.manager_file ()) =
FileDownloading
- && need_new_sources m then
- begin
- incr naneed;
- " and needs sources"
- end
- else "")
- ));
- ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar br", pos_to_string sready)) sreadylist) @
+ [ ("", "sr ar br", Printf.sprintf "%d" (list_sum sreadylist));
+ ("", "sr", Printf.sprintf "ready with %d active%s"
+ m.manager_active_sources
+ (if need_sources then " and needs sources"
+ else "")) ] );
Printf.bprintf buf "\\</tr\\>\n";
html_tr_same ();
-
html_mods_td buf (
- !streadylist
- @ [ ("", "sr ar br", Printf.sprintf "%d" !antready); ]
- @ [("", "sr", "throttled ready"); ]
- );
-
+ (List.map (fun sready ->
+ ("", "sr ar br", pos_to_string sready)) streadylist) @
+ [ ("", "sr ar br", string_of_int (list_sum streadylist));
+ ("", "sr", "throttled ready"); ] );
Printf.bprintf buf "\\</tr\\>\n";
- (if !anindirect <> 0 then
- begin
+ let anindirect = list_sum sindirectlist in
+ if anindirect <> 0 then begin
html_tr_same ();
html_mods_td buf (
- !sindirectlist
- @ [ ("", "sr ar br", Printf.sprintf "%d"
!anindirect); ]
- @ [ ("", "sr", "indirect"); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar br", pos_to_string sready)) sindirectlist) @
+ [ ("", "sr ar br", string_of_int anindirect);
+ ("", "sr", "indirect"); ] );
Printf.bprintf buf "\\</tr\\>\n";
- end
- );
+ end;
- (if !aninvalid <> 0 then
- begin
+ let aninvalid = list_sum sinvalidlist in
+ if aninvalid <> 0 then begin
html_tr_same ();
html_mods_td buf (
- !sinvalidlist
- @ [ ("", "sr ar br", Printf.sprintf "%d"
!aninvalid); ]
- @ [ ("", "sr", "invalid"); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar br", pos_to_string sready)) sinvalidlist) @
+ [ ("", "sr ar br", string_of_int aninvalid);
+ ("", "sr", "invalid"); ] );
Printf.bprintf buf "\\</tr\\>\n";
+ end;
end
- );
- end
- else
- begin
+ else begin
+ List.iter (Printf.bprintf buf "%4d ") slist;
Printf.bprintf buf "%4d %s\n" m.manager_all_sources name;
- Printf.bprintf buf "%s%4d ready %d active%s\n"
!sready !anready m.manager_active_sources
- (if file_state (m.manager_file ()) = FileDownloading
&& need_new_sources m then
- begin
- incr naneed;
- " needs sources"
+ List.iter (Printf.bprintf buf "%4d ") sreadylist;
+ Printf.bprintf buf "%4d ready %d active%s\n"
+ (list_sum sreadylist) m.manager_active_sources
+ (if need_sources then " needs sources"
+ else "");
+ List.iter (Printf.bprintf buf "%4d ") streadylist;
+ Printf.bprintf buf "%4d throttled ready\n"
+ (list_sum streadylist);
+ let anindirect = list_sum sindirectlist in
+ if anindirect <> 0 then begin
+ List.iter (Printf.bprintf buf "%4d ") sindirectlist;
+ Printf.bprintf buf "%4d indirect\n" anindirect;
+ end;
+ let aninvalid = list_sum sinvalidlist in
+ if aninvalid <> 0 then begin
+ List.iter (Printf.bprintf buf "%4d ") sinvalidlist;
+ Printf.bprintf buf "%4d invalid\n" aninvalid;
end
- else
- ""
- );
- Printf.bprintf buf "%s%4d throttled ready\n" !stready
!antready;
- if !anindirect <> 0 then
- Printf.bprintf buf "%s%4d indirect\n" !sindirect
!anindirect;
- if !aninvalid <> 0 then
- Printf.bprintf buf "%s%4d invalid\n" !sinvalid
!aninvalid;
end;
nall := !nall + m.manager_all_sources;
naact := !naact + m.manager_active_sources;
end
- else
- begin
-
- if output_type = HTML then
- begin
+ else begin (* m.manager_all_sources = 0 *)
+ if output_type = HTML then begin
html_tr ();
html_mods_td buf [
- ("", "sr ar br", "-"); ("", "sr ar br", ""); ("", "sr
ar br", "");
- ("", "sr ar br", ""); ("", "sr ar br", ""); ("", "sr
ar br", "");
- ("", "sr ar br", ""); ("", "sr ar br", ""); ("", "sr
ar br", "");
- ("", "sr ar br", ""); ("", "sr ar br", ""); ("", "sr
ar br", "");
- ("", "sr br", (shorten name !!max_name_len));
- ];
+ ("", "sr ar br", "-"); ("", "sr ar br", "");
+ ("", "sr ar br", ""); ("", "sr ar br", "");
+ ("", "sr ar br", ""); ("", "sr ar br", "");
+ ("", "sr ar br", ""); ("", "sr ar br", "");
+ ("", "sr ar br", ""); ("", "sr ar br", "");
+ ("", "sr ar br", ""); ("", "sr ar br", "");
+ ("", "sr br", shorten name !!max_name_len); ];
Printf.bprintf buf "\\</tr\\>\n";
end
- else
- Printf.bprintf buf "None %55s%s\n" ("") name;
- if file_state (m.manager_file ()) = FileDownloading &&
need_new_sources m then
- incr naneed;
+ else Printf.bprintf buf "None %55s%s\n" "" name;
end
) my_file_sources_managers; (* end Files *)
(* next Header *)
- if output_type = HTML then
- begin
+ if output_type = HTML then begin
Printf.bprintf buf "\\</table\\>\\</div\\>\n";
html_mods_table_header buf "sourcesTable" "sources" [
@@ -749,49 +716,14 @@
let sindirectlist = ref [] in
let sinvalidlist = ref [] in
let speriodlist = ref [] in
- let sready = ref "" in
- let stready = ref "" in
- let sindirect = ref "" in
- let sinvalid = ref "" in
- let speriod = ref "" in
- let anready = ref 0 in
- let antready = ref 0 in
- let anindirect = ref 0 in
- let aninvalid = ref 0 in
(* Queues *)
for i = 0 to nqueues - 1 do
- if output_type = HTML then
- begin
- slist := !slist @ [
- ("", "sr ar", (pos_to_string nsources_per_queue.(i))); ] ;
- sreadylist := !sreadylist @ [
- ("", "sr ar", (pos_to_string nready_per_queue.(i))); ] ;
- anready := !anready + nready_per_queue.(i);
- streadylist := !streadylist @ [
- ("", "sr ar", (pos_to_string (count_ready_sources i true))); ]
;
- antready := !antready + (count_ready_sources i true);
- sindirectlist := !sindirectlist @ [
- ("", "sr ar", (pos_to_string nindirect_per_queue.(i))); ] ;
- anindirect := !anindirect + nindirect_per_queue.(i);
- sinvalidlist := !sinvalidlist @ [
- ("", "sr ar", (pos_to_string ninvalid_per_queue.(i))); ] ;
- aninvalid := !aninvalid + ninvalid_per_queue.(i);
- speriodlist := !speriodlist @ [
- ("", "sr ar", (pos_to_string queue_period.(i))); ] ;
- end
- else
- begin
- Printf.bprintf buf "%4d " nsources_per_queue.(i);
- sready := Printf.sprintf "%s%4d " !sready nready_per_queue.(i);
- anready := !anready + nready_per_queue.(i);
- stready := Printf.sprintf "%s%4d " !stready (count_ready_sources
i true);
- antready := !antready + (count_ready_sources i true);
- sindirect := Printf.sprintf "%s%4d " !sindirect
nindirect_per_queue.(i);
- anindirect := !anindirect + nindirect_per_queue.(i);
- sinvalid := Printf.sprintf "%s%4d " !sinvalid
ninvalid_per_queue.(i);
- aninvalid := !aninvalid + ninvalid_per_queue.(i);
- speriod := Printf.sprintf "%s%4d " !speriod queue_period.(i);
- end;
+ slist := nsources_per_queue.(i) :: !slist;
+ sreadylist := nready_per_queue.(i) :: !sreadylist;
+ streadylist := count_ready_sources i true :: !streadylist;
+ sindirectlist := nindirect_per_queue.(i) :: !sindirectlist;
+ sinvalidlist := ninvalid_per_queue.(i) :: !sinvalidlist;
+ speriodlist := queue_period.(i) :: !speriodlist;
done; (* end Queues *)
let nsources = ref 0 in
@@ -804,101 +736,123 @@
) s.source_files;
) sources_by_uid;
- if output_type = HTML then
- begin
- html_tr();
+ let slist = List.rev !slist in
+ let sreadylist = List.rev !sreadylist in
+ let streadylist = List.rev !streadylist in
+ let sindirectlist = List.rev !sindirectlist in
+ let sinvalidlist = List.rev !sinvalidlist in
+ let speriodlist = List.rev !speriodlist in
+
+ if output_type = HTML then begin
+ html_tr ();
html_mods_td buf (
- !slist
- @ [ ("", "sr ar", Printf.sprintf "%d" !nall); ]
- @ [("", "sr", Printf.sprintf "all source managers (%d by UID)
(%d ROQ)" !nsources !nroq);]
- );
+ (List.map (fun q ->
+ ("", "sr ar", pos_to_string q)) slist) @
+ [ ("", "sr ar", Printf.sprintf "%d" !nall);
+ ("", "sr",
+ Printf.sprintf "all source managers (%d by UID) (%d ROQ)"
+ !nsources !nroq);] );
Printf.bprintf buf "\\</tr\\>\n";
html_tr ();
html_mods_td buf (
- !sreadylist
- @ [ ("", "sr ar", Printf.sprintf "%d" !anready); ]
- @ [ ("", "sr", Printf.sprintf "ready with %d active and %i need
sources" !naact !naneed); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar", pos_to_string sready)) sreadylist) @
+ [ ("", "sr ar", Printf.sprintf "%d" (list_sum sreadylist));
+ ("", "sr",
+ Printf.sprintf "ready with %d active and %i need sources"
+ !naact !naneed); ] );
Printf.bprintf buf "\\</tr\\>\n";
- html_tr();
+ html_tr ();
html_mods_td buf (
- !streadylist
- @ [ ("", "sr ar", Printf.sprintf "%d" !antready); ]
- @ [ ("", "sr", "throttled ready"); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar", pos_to_string sready)) streadylist) @
+ [ ("", "sr ar", Printf.sprintf "%d" (list_sum streadylist));
+ ("", "sr", "throttled ready"); ] );
Printf.bprintf buf "\\</tr\\>\n";
- (if !anindirect <> 0 then
- begin
+ let anindirect = list_sum sindirectlist in
+ if anindirect <> 0 then begin
html_tr ();
html_mods_td buf (
- !sindirectlist
- @ [ ("", "sr ar", Printf.sprintf "%d" !anindirect); ]
- @ [ ("", "sr", "indirect"); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar", pos_to_string sready)) sindirectlist) @
+ [ ("", "sr ar", Printf.sprintf "%d" anindirect);
+ ("", "sr", "indirect"); ] );
Printf.bprintf buf "\\</tr\\>\n";
- end
- );
+ end;
- (if !aninvalid <> 0 then
- begin
+ let aninvalid = list_sum sinvalidlist in
+ if aninvalid <> 0 then begin
html_tr ();
html_mods_td buf (
- !sinvalidlist
- @ [ ("", "sr ar", Printf.sprintf "%d" !aninvalid); ]
- @ [ ("", "sr", "invalid"); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar", pos_to_string sready)) sinvalidlist) @
+ [ ("", "sr ar", Printf.sprintf "%d" aninvalid);
+ ("", "sr", "invalid"); ] );
Printf.bprintf buf "\\</tr\\>\n";
- end
- );
+ end;
html_tr ();
html_mods_td buf (
- !speriodlist
- @ [ ("", "sr", "") ]
- @ [("", "sr", "period"); ]
- );
+ (List.map (fun sready ->
+ ("", "sr ar", pos_to_string sready)) speriodlist) @
+ [ ("", "sr", "");
+ ("", "sr", "period"); ] );
Printf.bprintf buf "\\</tr\\>\n";
Printf.bprintf buf "\\</table\\>\\</div\\>\n";
end
- else
- begin
- Printf.bprintf buf "%4d all source managers (%d by UID) (%d
ROQ)\n" !nall !nsources !nroq;
- Printf.bprintf buf "%s%4d ready %d active %i need sources\n"
!sready !anready !naact !naneed;
- Printf.bprintf buf "%s%4d throttled ready\n" !stready
!antready;
- if !anindirect <> 0 then
- Printf.bprintf buf "%s%4d indirect\n" !sindirect !anindirect;
- if !aninvalid <> 0 then
- Printf.bprintf buf "%s%4d invalid\n" !sinvalid !aninvalid;
- Printf.bprintf buf "%s period\n" !speriod;
+ else begin
+ List.iter (Printf.bprintf buf "%4d ") slist;
+ Printf.bprintf buf "%4d all source managers (%d by UID) (%d ROQ)\n"
+ !nall !nsources !nroq;
+ List.iter (Printf.bprintf buf "%4d ") sreadylist;
+ Printf.bprintf buf "%4d ready %d active %i need sources\n"
+ (list_sum sreadylist) !naact !naneed;
+ List.iter (Printf.bprintf buf "%4d ") streadylist;
+ Printf.bprintf buf "%4d throttled ready\n" (list_sum streadylist);
+ let anindirect = list_sum sindirectlist in
+ if anindirect <> 0 then begin
+ List.iter (Printf.bprintf buf "%4d ") sindirectlist;
+ Printf.bprintf buf "%4d indirect\n" anindirect;
end;
+ let aninvalid = list_sum sinvalidlist in
+ if aninvalid <> 0 then begin
+ List.iter (Printf.bprintf buf "%4d ") sinvalidlist;
+ Printf.bprintf buf "%4d invalid\n" aninvalid;
+ end;
+ List.iter (Printf.bprintf buf "%4d ") speriodlist;
+ Printf.bprintf buf " period\n";
+ end;
+
let nconnected = ref 0 in
- Fifo.iter
- (fun (_,s) ->
+ Fifo.iter (fun (_, s) ->
if s.source_last_attempt = 0 then incr nconnected;
) connecting_sources;
- if output_type = HTML then
- begin
+ if output_type = HTML then begin
html_mods_table_header buf "sourcesTable" "sources" [
( "0", "srh", "Connecting sources", "Connecting sources" );
( "0", "srh", "Next direct sources", "Next direct sources" );
( "0", "srh", "Next indirect sources", "Next indirect sources"
); ];
Printf.bprintf buf "\\<tr class=\\\"dl-1\\\"\\>";
html_mods_td buf [
- ("", "sr", (Printf.sprintf "%d entries" (Fifo.length
connecting_sources)) ^
- (if !nconnected > 0 then Printf.sprintf " (connected: %d)"
!nconnected else ("")));
- ("", "sr", Printf.sprintf "%d entries" (Fifo.length
next_direct_sources));
- ("", "sr", Printf.sprintf "%d entries" (List.length
!next_indirect_sources)); ];
+ ("", "sr", (Printf.sprintf "%d entries"
+ (Fifo.length connecting_sources)) ^
+ (if !nconnected > 0 then
+ Printf.sprintf " (connected: %d)" !nconnected else ""));
+ ("", "sr", Printf.sprintf "%d entries"
+ (Fifo.length next_direct_sources));
+ ("", "sr", Printf.sprintf "%d entries"
+ (List.length !next_indirect_sources)); ];
Printf.bprintf buf "\\</tr\\>\\</table\\>\\</div\\>\n\\</div\\>"
end
- else
- begin
+ else begin
Printf.bprintf buf "Connecting Sources: %d entries"
(Fifo.length connecting_sources);
- if !nconnected > 0 then Printf.bprintf buf " (connected: %d)"
!nconnected;
+ if !nconnected > 0 then
+ Printf.bprintf buf " (connected: %d)" !nconnected;
Printf.bprintf buf "\n";
Printf.bprintf buf "Next Direct Sources: %d entries\n"
(Fifo.length next_direct_sources);
@@ -916,10 +870,8 @@
let reschedule_source_for_file saved s r =
if r.request_queue = outside_queue then
let queue =
- if r.request_score = not_found_score then
- do_not_try_queue
- else if s.source_last_attempt <> 0 then
- connecting_sources_queue
+ if r.request_score = not_found_score then do_not_try_queue
+ else if s.source_last_attempt <> 0 then connecting_sources_queue
else
match s.source_sock with
| (NoConnection | ConnectionWaiting _) ->
@@ -934,34 +886,22 @@
rank. *)
if r.request_score > found_score then
if saved then
- if
- r.request_time + !!min_reask_delay < last_time ()
- then
+ if r.request_time + !!min_reask_delay < last_time ()
then
ready_saved_sources_queue
- else
- waiting_saved_sources_queue
- else
- if r.request_score = initial_new_source_score then
+ else waiting_saved_sources_queue
+ else if r.request_score = initial_new_source_score then
new_sources_queue
- else
- good_sources_queue
- else
- if r.request_score >= new_source_score then
+ else good_sources_queue
+ else if r.request_score >= new_source_score then
old_sources1_queue
- else
- old_sources2_queue
- else
- if s.source_score < 5 then
- old_sources3_queue
- else
- do_not_try_queue
+ else old_sources2_queue
+ else if s.source_score < 5 then old_sources3_queue
+ else do_not_try_queue
| Connection _ ->
(* State (3) *)
- if r.request_time = 0 then
- busy_sources_queue
- else
- connected_sources_queue
+ if r.request_time = 0 then busy_sources_queue
+ else connected_sources_queue
in
let m = r.request_file in
if !verbose_sources > 1 then
@@ -981,7 +921,7 @@
let iter_all_sources f m =
Array.iter (fun q ->
- Queue.iter (fun (_,s) -> f s) q
+ Queue.iter (fun (_, s) -> f s) q
) m.manager_sources
(*************************************************************************)
@@ -990,7 +930,7 @@
(*************************************************************************)
let iter_qualified_sources f m =
let q = m.manager_sources.(good_sources_queue) in
- Queue.iter (fun (_,s) -> f s) q
+ Queue.iter (fun (_, s) -> f s) q
(*************************************************************************)
(* *)
@@ -1001,7 +941,7 @@
let iter_active_sources f m =
for i = connected_sources_queue to busy_sources_queue do
let q = m.manager_sources.(i) in
- Queue.iter (fun (_,s) -> f s) q
+ Queue.iter (fun (_, s) -> f s) q
done
(*************************************************************************)
@@ -1013,7 +953,7 @@
List.iter (fun i ->
if i < nqueues then
let q = m.manager_sources.(i) in
- Queue.iter (fun (_,s) -> f s) q
+ Queue.iter (fun (_, s) -> f s) q
) !!relevant_queues
(*************************************************************************)
@@ -1086,10 +1026,9 @@
file f2 is paused we connect because of f1 and then query both
files f1 and f2 ... and yes, we do a cleanup ... but a timed one,
so we can't be sure *)
- if r.request_score > not_found_score
- && file_state (r.request_file.manager_file ()) = FileDownloading
- then
- begin
+ if r.request_score > not_found_score &&
+ file_state (r.request_file.manager_file ()) = FileDownloading
+ then begin
r.request_time <- 0; (* The source is ready for this request *)
reschedule_source_for_file false s r; (* put it in
busy_sources_queue *)
(try
@@ -1127,8 +1066,8 @@
functions.function_add_location s.source_uid
m.manager_uid with _ -> ());
reschedule_source_for_file false s r
- end (* else
- lprintf "outside queue\n" *)
+ end
+ (* else lprintf "outside queue\n" *)
) s.source_files
(*************************************************************************)
@@ -1140,7 +1079,7 @@
(* From states (1) or (2) to state (3) *)
let source_disconnected s =
(match s.source_sock with
- NoConnection -> ()
+ | NoConnection -> ()
| ConnectionWaiting token ->
cancel_token token;
s.source_sock <- NoConnection
@@ -1155,17 +1094,14 @@
*)
s.source_last_attempt <- 0;
List.iter (fun r ->
- if r.request_queue <> outside_queue then
- begin
+ if r.request_queue <> outside_queue then begin
remove_from_queue s r;
- if connecting then
- begin
+ if connecting then begin
r.request_time <- last_time ();
if r.request_score = initial_new_source_score then
set_score_part r new_source_score
end
- else
- begin
+ else begin
if r.request_time = 0 then
(* we think we were not connecting,
but in some cases we were! and
@@ -1179,8 +1115,7 @@
let m = r.request_file in
functions.function_remove_location s.source_uid
m.manager_uid
- with _ -> ()
- )
+ with _ -> ())
end;
reschedule_source_for_file false s r;
end;
@@ -1263,15 +1198,11 @@
(*************************************************************************)
let remove_file_sources_manager m =
-
iter_all_sources (fun s ->
- s.source_files <- List.filter (fun r ->
- r.request_file != m
- ) s.source_files;
+ s.source_files <-
+ List.filter (fun r -> r.request_file != m) s.source_files;
) m;
-
m.manager_sources <- create_queues ();
-
file_sources_managers := List2.removeq m !file_sources_managers
@@ -1280,7 +1211,7 @@
(* number_of_sources *)
(* *)
(*************************************************************************)
-(* get number of sources for a file*)
+ (* get number of sources for a file*)
let number_of_sources f =
f.manager_all_sources
@@ -1293,10 +1224,9 @@
let find_source_by_uid uid =
try
let finder = { dummy_source with source_uid = uid } in
- let s = HS.find sources_by_uid finder in
- s
+ HS.find sources_by_uid finder
- with _ ->
+ with Not_found ->
if !verbose_sources > 1 then
lprintf_nl "[cSrc] Creating new source";
let n = CommonClient.book_client_num () in
@@ -1306,8 +1236,6 @@
source_num = n;
source_files = [];
} in
-
-
HS.add sources_by_uid s;
H.add sources_by_num s;
s
@@ -1320,8 +1248,7 @@
let find_source_by_num num =
let finder = { dummy_source with source_num = num } in
- let s = H.find sources_by_num finder in
- s
+ H.find sources_by_num finder
(*************************************************************************)
(* *)
@@ -1331,10 +1258,10 @@
let rec iter_has_request rs file =
match rs with
- [] -> raise Not_found
+ | [] -> raise Not_found
| r :: tail ->
- if r.request_file == file then r else
- iter_has_request tail file
+ if r.request_file == file then r
+ else iter_has_request tail file
let find_request s file =
iter_has_request s.source_files file
@@ -1348,12 +1275,12 @@
let find_request_result s file =
let r = find_request s file in
let score = r.request_score in
- if score <= not_found_score then File_not_found else
- if score <= possible_score then File_possible else
- if score <= found_score then File_found else
- if score <= chunk_score then File_chunk else
- if score <= initial_new_source_score then File_new_source else
- assert false
+ if score <= not_found_score then File_not_found
+ else if score <= possible_score then File_possible
+ else if score <= found_score then File_found
+ else if score <= chunk_score then File_chunk
+ else if score <= initial_new_source_score then File_new_source
+ else assert false
(*************************************************************************)
(* *)
@@ -1362,10 +1289,8 @@
(*************************************************************************)
let check_time time =
- if time = 0 then
- last_time () - 650
- else
- time (* changed 2.5.24 *)
+ if time = 0 then last_time () - 650
+ else time (* changed 2.5.24 *)
let add_request s file time =
let r =
@@ -1374,8 +1299,7 @@
remove_from_queue s r;
set_score_part r (if r.request_score = initial_new_source_score
then
new_source_score
- else
- r.request_score - 1);
+ else r.request_score - 1);
r.request_time <- check_time time;
r
with Not_found ->
@@ -1386,8 +1310,7 @@
request_queue = outside_queue;
} in
s.source_files <- r :: s.source_files;
- r
- in
+ r in
reschedule_source_for_file false s r;
r
@@ -1405,18 +1328,17 @@
announced as new, just forget it. : why half-hour? - trying min_reask_delay
*)
score = initial_new_source_score &&
r.request_time + !!min_reask_delay > last_time ()
- ))
+ )) ||
(* If a file has been paused, and resumed, it is flagged outside_queue /
not_found_score in
clean_sources, but really should be re-added to the queues as soon as
possible (while retaining
its request_time) or it is skipped for far too long (if it is even found
again) - reschedule
now puts new_source_score in old1 *)
- || (score = initial_new_source_score
- && r.request_queue = outside_queue) then
+ (score = initial_new_source_score &&
+ r.request_queue = outside_queue) then
let score =
if score = initial_new_source_score
then new_source_score
- else score
- in
+ else score in
if r.request_queue < connected_sources_queue then
remove_from_queue s r;
set_score_part r score;
@@ -1439,8 +1361,9 @@
(*************************************************************************)
let set_request_result s file result =
- set_request_score s file (match result with
- File_not_found -> not_found_score
+ set_request_score s file
+ (match result with
+ | File_not_found -> not_found_score
| File_found -> found_score
| File_chunk -> chunk_score
| File_upload -> upload_score
@@ -1457,14 +1380,12 @@
let requests = ref [] in
List.iter (fun r ->
if r.request_score > possible_score then
-
requests :=
(SmallList
[once_value (string_to_value r.request_file.manager_uid);
int_to_value r.request_score;
int_to_value r.request_time]
- ) ::
- !requests
+ ) :: !requests
) s.source_files;
if !requests = [] then raise Exit;
(
@@ -1500,7 +1421,7 @@
(* query_files *)
(* *)
(*************************************************************************)
-(* Query a source for all of its known files*)
+ (* Query a source for all of its known files*)
let query_files s =
List.iter (fun f ->
query_file s f.request_file;
@@ -1546,8 +1467,7 @@
(value_to_list (fun s -> s)) in
let last_conn =
- try get_value "age" value_to_int with _ -> 0
- in
+ try get_value "age" value_to_int with _ -> 0 in
let score = try get_value "sscore" value_to_int with _ -> 0 in
let brand = try get_value "brand" M.value_to_source_brand with _ ->
@@ -1564,7 +1484,7 @@
let rec iter v =
match v with
- OnceValue v -> iter v
+ | OnceValue v -> iter v
| List [uid; score; time] | SmallList [uid; score; time] ->
(try
let uid = value_to_string uid in
@@ -1573,19 +1493,17 @@
(* added in 2.5.27 to fix a bug introduced in 2.5.25 *)
let score =
- if score land 0xffff = 0 then score asr 16 else score
- in
+ if score land 0xffff = 0 then score asr 16 else score in
(* lprintf "(3) value_to_source \n"; *)
add_saved_source_request s uid score time
with e ->
- if !verbose_sources > 1 then begin
+ if !verbose_sources > 1 then
lprintf_nl "[cSrc] CommonSources.value_to_source:
exception %s in iter request"
- (Printexc2.to_string e);
- end
- )
+ (Printexc2.to_string e))
+
| (StringValue _) as uid ->
(try
let uid = value_to_string uid in
@@ -1596,19 +1514,16 @@
add_saved_source_request s uid score time
with e ->
- if !verbose_sources > 1 then begin
+ if !verbose_sources > 1 then
lprintf_nl "[cSrc] CommonSources.value_to_source:
exception %s in iter request"
- (Printexc2.to_string e);
- end
- )
+ (Printexc2.to_string e))
+
| _ -> assert false
in
(* lprintf "(5) value_to_source \n"; *)
-
List.iter iter files;
(* lprintf "(6) value_to_source \n"; *)
-
raise SideEffectOption
(*************************************************************************)
@@ -1658,30 +1573,26 @@
let (request_time, s) = Queue.head q in
let throttled = queue_period.(queue) > 0 && nsource > 1 in
let throttle_delay = get_throttle_delay m queue throttled in
- if request_time + !!min_reask_delay + throttle_delay <
last_time () then
- begin
+ if request_time + !!min_reask_delay + throttle_delay <
last_time () then begin
if !verbose_sources > 1 then
lprintf_nl "[cSrc] Sources: take source from Queue[%s]
for %s"
queue_name.(queue)
(file_best_name (m.manager_file ()));
(* put in the connecting queue*)
source_connecting s;
- if M.direct_source s.source_uid then
- begin
+ if M.direct_source s.source_uid then begin
Fifo.put next_direct_sources s;
(* we found a direct source try again in the _same_
queue *)
get_sources (nsource-1) m queue (took+1)
end
- else
- begin
+ else begin
next_indirect_sources := s :: !next_indirect_sources;
(* we found an indirect source try again in the _same_
queue. indirect sources are "for free". *)
get_sources nsource m queue took
end
end
- else
- begin
+ else begin
if !verbose_sources > 1 then
lprintf_nl "[cSrc] Source of queue %s is not ready for
%s"
queue_name.(queue) (file_best_name (m.manager_file
()));
@@ -1690,11 +1601,8 @@
(* queue not throttled, try next queue *)
let to_take =
(* a maximum of just one source from old3 queue *)
- if queue+1 >= old_sources3_queue then
- (min 1 nsource)
- else
- nsource
- in
+ if queue+1 >= old_sources3_queue then min 1 nsource
+ else nsource in
get_sources to_take m (queue+1) took
else
(* throttled queue, and no ready sources ... *)
@@ -1706,22 +1614,17 @@
(* finaly try to take at least one source,
regardless of throttles *)
get_sources 1 m (queue) took
end
- else
- begin
+ else begin
if !verbose_sources > 1 then
lprintf_nl "[cSrc] Queue %s is empty for %s"
queue_name.(queue) (file_best_name (m.manager_file ()));
(* no sources in this queue try again in the _next_ queue *)
let to_take =
(* a maximum of just one source from old3 queue *)
- if queue+1 >= old_sources3_queue then
- (min 1 nsource)
- else
- nsource
- in
+ if queue+1 >= old_sources3_queue then min 1 nsource
+ else nsource in
get_sources to_take m (queue+1) took
- end
- in
+ end in
(* recalc list if there's no new file*)
(* Fill only with sources from files being downloaded *)
@@ -1732,41 +1635,38 @@
let sum_priority = ref 0 in
List.iter (fun m ->
match file_state (m.manager_file ()) with
- FileDownloading ->
+ | FileDownloading ->
let priority = file_priority (m.manager_file ()) in
min_priority := min !min_priority priority;
sum_priority := !sum_priority + priority;
files := (priority, m ) :: !files;
incr nfiles
- | _ -> ()
- ) !file_sources_managers;
+ | _ -> () ) !file_sources_managers;
if !files <> [] then begin
(* 'normalize' to 0 priorities*)
sum_priority := !sum_priority + (!nfiles * (-(!min_priority)));
(* update priorities to be > 0 *)
- files := List.map ( fun (p,f) ->
+ files := List.map (fun (p, f) ->
let np = p - (!min_priority) in
- if np==0 then
- begin
- sum_priority := !sum_priority + 1;
- (1,f)
+ if np = 0 then begin
+ incr sum_priority;
+ (1, f)
end
- else
- (np,f)
- ) !files;
+ else (np, f) ) !files;
(*sort by highest priority*)
files := List.sort (fun (p1,_) (p2,_) -> compare p2 p1) !files;
(* calc sources queue size
at least 3 sources per file*)
- let nsources = max (!nfiles*3)
+ let nsources = max (!nfiles * 3)
(functions.function_max_connections_per_second () * 10) in
(* calc how much sources a file can get according to its priority*)
- let sources_per_prio = (float_of_int nsources) /. (float_of_int
!sum_priority) in
+ let sources_per_prio =
+ (float_of_int nsources) /. (float_of_int !sum_priority) in
(*
@@ -1784,8 +1684,7 @@
from SE *)
let try_some_new_sources () =
let extr = ref 0 in
- List.iter
- (fun m ->
+ List.iter (fun m ->
let f = m.manager_file () in
let q = m.manager_sources.(new_sources_queue) in
if file_state f = FileDownloading && Queue.length q > 0
then
@@ -1802,8 +1701,7 @@
let cleanup_some_old_sources () =
(* Cleanup some sources *)
- List.iter
- (fun m ->
+ List.iter (fun m ->
let f = m.manager_file () in
if file_state f = FileDownloading then
let remove_old q t =
@@ -1818,12 +1716,12 @@
) !file_sources_managers in
let rec aux flist_todo assigned =
- if assigned >= nsources then
- cleanup_some_old_sources ()
+ if assigned >= nsources then cleanup_some_old_sources ()
else
match flist_todo with
| (prio, file) :: t ->
- let tt = min (truncate (sources_per_prio *.
(float_of_int prio)))
+ let tt =
+ min (truncate (sources_per_prio *. (float_of_int prio)))
max_consecutive in
let to_take = max tt 1 in
(* allow at least one source per file :
@@ -1862,26 +1760,21 @@
(* adjust queue throttling *)
let all_ready = ref 0 in
- List.iter
- (fun q ->
+ List.iter (fun q ->
let queue_throttled_ready = count_ready_sources q true in
let queue_ready = count_ready_sources q false in
all_ready := !all_ready + queue_throttled_ready;
- if !all_ready > nsources && queue_throttled_ready > 0 then
+ if !all_ready > nsources && queue_throttled_ready > 0 then begin
(* no need, to increase period on a queue without ready
sources *)
- begin
(* lprintf "commonSources: increasing queue throttling for
(ar=%d rc=%d qr=%d) %s\n" !allReady nsources queueReady queue_name.(q); *)
queue_period.( q ) <- queue_period.( q ) + 1
end
- else
- begin
- if queue_ready = 0 then
- begin
+ else begin
+ if queue_ready = 0 then begin
(* lprintf "commonSources: resetting queue throttling
to 0 (ar=%d rc=%d qr=%d) %s\n" !allReady nsources queueReady queue_name.(q); *)
queue_period.( q ) <- 0
end
- else
- begin
+ else begin
(* lprintf "commonSources: decreasing queue throttling
for (ar=%d rc=%d qr=%d) %s\n" !allReady nsources queueReady queue_name.(q); *)
queue_period.( q ) <- max 0 (queue_period.( q ) - 1)
end
@@ -1906,15 +1799,13 @@
(* clean_sources helper *)
(* *)
(*************************************************************************)
-let put_all_outside_queue m q queue =
+ let put_all_outside_queue m q queue =
let _, s = Queue.take q in
m.manager_all_sources <- m.manager_all_sources - 1;
if active_queue queue then
m.manager_active_sources <- m.manager_active_sources - 1;
- List.iter
- (fun r ->
- if r.request_file == m then
- begin
+ List.iter (fun r ->
+ if r.request_file == m then begin
r.request_queue <- outside_queue;
set_score_part r not_found_score
end
@@ -1929,36 +1820,32 @@
let clean_sources () =
(* Maybe this should be dependant on the file (priority, state,...) ?
*)
let max_sources_per_file = functions.function_max_sources_per_file ()
in
- List.iter
- (fun m ->
+ List.iter (fun m ->
match file_state (m.manager_file ()) with
- FileDownloading ->
+ | FileDownloading ->
let nsources = m.manager_all_sources in
if nsources > max_sources_per_file then
let rec iter nsources q queue =
if nsources > 0 then
- if Queue.length q > 0
- && queue <> good_sources_queue
- then
- begin
+ if Queue.length q > 0 &&
+ queue <> good_sources_queue then begin
put_all_outside_queue m q queue;
iter (nsources-1) q queue
end
else
let do_iter q = iter nsources m.manager_sources.(q) q in
- if queue = old_sources1_queue then do_iter
do_not_try_queue else
- if queue = do_not_try_queue then do_iter
new_sources_queue else
- if queue = new_sources_queue then do_iter
waiting_saved_sources_queue else
- if queue > good_sources_queue then do_iter (queue-1)
+ if queue = old_sources1_queue then do_iter
do_not_try_queue
+ else if queue = do_not_try_queue then do_iter
new_sources_queue
+ else if queue = new_sources_queue then do_iter
waiting_saved_sources_queue
+ else if queue > good_sources_queue then do_iter (queue-1)
in
iter (nsources - max_sources_per_file)
(m.manager_sources.(old_sources3_queue)) old_sources3_queue
| _ ->
let rec iter q queue =
- if Queue.length q > 0 then
- begin
+ if Queue.length q > 0 then begin
put_all_outside_queue m q queue;
iter q queue
end
@@ -1989,8 +1876,8 @@
if time <> s.source_last_attempt then begin
ignore (Fifo.take connecting_sources);
iter ()
- end else
- if time + 120 < last_time () then begin
+ end
+ else if time + 120 < last_time () then begin
ignore (Fifo.take connecting_sources);
if s.source_last_attempt <> 0 then source_disconnected s;
iter ()
@@ -2015,7 +1902,7 @@
lprintf_nl "[cSrc] query connected sources...";
List.iter (fun m ->
match file_state (m.manager_file ()) with
- FileDownloading ->
+ | FileDownloading ->
let q = m.manager_sources.(connected_sources_queue) in
let rec iter () =
if Queue.length q > 0 then
@@ -2035,15 +1922,14 @@
This seems thus safe.
*)
iter ()
- end
- in
+ end in
iter ()
| _ -> ()
) !file_sources_managers;
if !verbose_sources > 1 then
lprintf_nl "[cSrc] connect to sources...";
-(* Finally, connect to available sources *)
+ (* Finally, connect to available sources *)
try
let max_sources = functions.function_max_connections_per_second () in
if !verbose_sources > 1 then
@@ -2053,19 +1939,17 @@
if Fifo.length next_direct_sources > 0 then
let s = Fifo.take next_direct_sources in
connect_source s;
- let nsources = match s.source_sock with
- NoConnection ->
+ let nsources =
+ match s.source_sock with
+ | NoConnection ->
if !verbose_sources > 1 then
lprintf_nl "[cSrc] not connected"; nsources
- | _ -> nsources-1
- in
+ | _ -> nsources - 1 in
iter nsources refilled
- else
- if not refilled then begin
+ else if not refilled then begin
refill_sources ();
iter nsources true
- end
- in
+ end in
iter max_sources false;
if !verbose_sources > 1 then
lprintf_nl "[cSrc] done connect_sources";
@@ -2081,7 +1965,7 @@
let value_to_module f v =
match v with
- Module list -> f list
+ | Module list -> f list
| _ -> failwith "Option should be a module"
let option = define_option_class "Source"
@@ -2095,16 +1979,14 @@
let attach_sources_to_file section =
(* lprintf "attach_sources_to_file\n"; *)
let sources = match !file_sources_option with
- None ->
+ | None ->
(* lprintf "attaching sources this time\n"; *)
let sources = define_option section
- ["sources"] "" (listiter_option option) []
- in
+ ["sources"] "" (listiter_option option) [] in
(* lprintf "done\n"; *)
file_sources_option := Some sources;
sources
- | Some sources -> sources
- in
+ | Some sources -> sources in
sources =:= [];
HS.iter (fun s -> sources =:= s :: !!sources) sources_by_uid;
@@ -2117,7 +1999,7 @@
(* *)
(*************************************************************************)
- let _ =
+ let () =
Heap.add_memstat M.module_name (fun level buf ->
let nsources_per_queue = Array.create nqueues 0 in
@@ -2130,10 +2012,8 @@
let ready_threshold = last_time () - !!min_reask_delay in
Queue.iter (fun (time, s) ->
incr nsources;
- if time < ready_threshold then
- incr nready
- else
- if i = new_sources_queue then begin
+ if time < ready_threshold then incr nready
+ else if i = new_sources_queue then begin
Printf.bprintf buf "ERROR: Source is not ready in
new_sources_queue !\n";
print_source buf s
end
@@ -2147,43 +2027,33 @@
for i = 0 to nqueues - 1 do
Printf.bprintf buf " Queue[%s]: %d entries (%d ready)\n"
queue_name.(i) nsources_per_queue.(i) nready_per_queue.(i);
-
done;
let nsources = ref 0 in
HS.iter (fun _ -> incr nsources) sources_by_uid;
Printf.bprintf buf "Sources by UID table: %d entries\n" !nsources;
+ let a1, a2, a3, a4, a5, a6 = HS.stats sources_by_uid in
Printf.bprintf buf "Sources by UID table stats: %d %d %d %d %d
%d\n"
- ((fun (n,_,_,_,_,_) -> n)(HS.stats sources_by_uid))
- ((fun (_,n,_,_,_,_) -> n)(HS.stats sources_by_uid))
- ((fun (_,_,n,_,_,_) -> n)(HS.stats sources_by_uid))
- ((fun (_,_,_,n,_,_) -> n)(HS.stats sources_by_uid))
- ((fun (_,_,_,_,n,_) -> n)(HS.stats sources_by_uid))
- ((fun (_,_,_,_,_,n) -> n)(HS.stats sources_by_uid))
- ;
+ a1 a2 a3 a4 a5 a6;
nsources := 0;
H.iter (fun _ -> incr nsources) sources_by_num;
Printf.bprintf buf "Sources by NUM table: %d entries\n" !nsources;
+ let a1, a2, a3, a4, a5, a6 = H.stats sources_by_num in
Printf.bprintf buf "Sources by NUM table stats: %d %d %d %d %d
%d\n"
- ((fun (n,_,_,_,_,_) -> n)(H.stats sources_by_num))
- ((fun (_,n,_,_,_,_) -> n)(H.stats sources_by_num))
- ((fun (_,_,n,_,_,_) -> n)(H.stats sources_by_num))
- ((fun (_,_,_,n,_,_) -> n)(H.stats sources_by_num))
- ((fun (_,_,_,_,n,_) -> n)(H.stats sources_by_num))
- ((fun (_,_,_,_,_,n) -> n)(H.stats sources_by_num))
- ;
+ a1 a2 a3 a4 a5 a6;
Printf.bprintf buf "Used indirect connections: %d\n"
!indirect_connections;
let nconnected = ref 0 in
- Fifo.iter (fun (_,s) ->
+ Fifo.iter (fun (_, s) ->
if s.source_last_attempt = 0 then incr nconnected;
) connecting_sources;
Printf.bprintf buf "Connecting Sources: %d entries"
(Fifo.length connecting_sources);
- if !nconnected > 0 then Printf.bprintf buf " (connected: %d)"
!nconnected;
+ if !nconnected > 0 then
+ Printf.bprintf buf " (connected: %d)" !nconnected;
Printf.bprintf buf "\n";
Printf.bprintf buf "Next Direct Sources: %d entries\n"
Index: src/daemon/common/commonSources.mli
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonSources.mli,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- src/daemon/common/commonSources.mli 8 Apr 2006 02:16:21 -0000 1.10
+++ src/daemon/common/commonSources.mli 3 Dec 2006 20:47:12 -0000 1.11
@@ -16,19 +16,8 @@
along with mldonkey; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
-
-open Queues
-open Printf2
-open Md4
-open Options
-open BasicSocket
-
-open TcpBufferedSocket
-open CommonFile
-open CommonOptions
open CommonTypes
-
type request_result =
| File_possible (* we asked, but didn't know *)
| File_not_found (* we asked, the file is not there *)
@@ -38,11 +27,10 @@
| File_upload (* we uploaded from this client *)
(* | File_unknown We don't know anything *)
- (*
+(*
val initial_new_source_score : int
val new_source_score : int
val not_found_score : int
-val possible_score : int
val found_score : int
val chunk_score : int
val upload_score : int
@@ -63,15 +51,16 @@
(*************************************************************************)
sig
-
val module_name : string
type source_uid
+
val dummy_source_uid : source_uid
val source_uid_to_value: source_uid -> Options.option_value
val value_to_source_uid: Options.option_value -> source_uid
type source_brand
+
val dummy_source_brand : source_brand
val source_brand_to_value: source_brand -> Options.option_value
val value_to_source_brand: Options.option_value -> source_brand
@@ -132,29 +121,26 @@
val functions : functions
- val create_file_sources_manager :
- string -> file_sources_manager
- val remove_file_sources_manager :
- file_sources_manager -> unit
- val number_of_sources :
- file_sources_manager -> int
-
+ val create_file_sources_manager : string -> file_sources_manager
+ val remove_file_sources_manager : file_sources_manager -> unit
+(*
+ val number_of_sources : file_sources_manager -> int
+*)
(* Find a given source *)
+
val find_source_by_uid : M.source_uid -> source
+(*
val find_source_by_num : int -> source
-
+*)
(* Feed-back on sources *)
val source_connected : source -> unit
val source_disconnected : source -> unit
- val add_request :
- source -> file_sources_manager -> int -> file_request
+ val add_request : source -> file_sources_manager -> int -> file_request
val set_request_result :
source -> file_sources_manager -> request_result -> unit
- val find_request :
- source -> file_sources_manager -> file_request
- val find_request_result :
- source -> file_sources_manager -> request_result
+ val find_request : source -> file_sources_manager -> file_request
+ val find_request_result : source -> file_sources_manager -> request_result
val need_new_sources : file_sources_manager -> bool
@@ -168,16 +154,19 @@
val indirect_connections : int ref
val dummy_source : source
-
+(*
val query_file : source -> file_sources_manager -> unit
+*)
val query_files : source -> unit
val clean_sources : unit -> unit
val iter_all_sources : (source -> unit) -> file_sources_manager -> unit
val iter_active_sources : (source -> unit) -> file_sources_manager ->
unit
- val iter_qualified_sources : (source -> unit) -> file_sources_manager ->
unit
- val iter_relevant_sources : (source -> unit) ->
file_sources_manager -> unit
+ val iter_qualified_sources :
+ (source -> unit) -> file_sources_manager -> unit
+ val iter_relevant_sources :
+ (source -> unit) -> file_sources_manager -> unit
val source_brand : source -> M.source_brand
val set_source_brand : source -> M.source_brand -> unit