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: Thu, 25 Jan 2007 13:09:16 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       07/01/25 13:09:16

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonOptions.ml commonSwarming.ml 

Log message:
        patch #5642

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.1162&r2=1.1163
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonOptions.ml?cvsroot=mldonkey&r1=1.194&r2=1.195
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonSwarming.ml?cvsroot=mldonkey&r1=1.56&r2=1.57

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.1162
retrieving revision 1.1163
diff -u -b -r1.1162 -r1.1163
--- distrib/ChangeLog   25 Jan 2007 13:06:45 -0000      1.1162
+++ distrib/ChangeLog   25 Jan 2007 13:09:16 -0000      1.1163
@@ -15,6 +15,11 @@
 =========
 
 2007/01/25
+5642: Swarmer: swarming_block_selection_algorithm = 3 (TripleM)
+- this new algorithm select always the rarest choice, if average availability
+  is below 5, or one choice_availability is below average availability
+- added a hashtable to store blockmaps of uploaders for a given swarmer
+- long term memory usage has to be observed
 5710: Swarmer: Fix chunk propagation (pango)
 
 2007/01/21

Index: src/daemon/common/commonOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonOptions.ml,v
retrieving revision 1.194
retrieving revision 1.195
diff -u -b -r1.194 -r1.195
--- src/daemon/common/commonOptions.ml  15 Jan 2007 18:26:27 -0000      1.194
+++ src/daemon/common/commonOptions.ml  25 Jan 2007 13:09:16 -0000      1.195
@@ -1187,7 +1187,7 @@
     int_option 3
 
 let swarming_block_selection_algorithm = define_expert_option current_section 
["swarming_block_selection_algorithm"]
-  "What algorithm to use to select blocks (currently 1 or 2)"
+  "What algorithm to use to select blocks (currently 1, 2 or 3)"
     int_option 1
 
 let block_switching = define_expert_option current_section ["block_switching"]
@@ -1777,7 +1777,7 @@
   );
   option_hook swarming_block_selection_algorithm (fun _ ->
     match !!swarming_block_selection_algorithm with
-    | 1 | 2 -> ()
+    | 1 | 2 | 3 -> ()
     | _ -> swarming_block_selection_algorithm =:= 1;
   );
   option_hook max_upload_slots (fun _ ->

Index: src/daemon/common/commonSwarming.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonSwarming.ml,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- src/daemon/common/commonSwarming.ml 25 Jan 2007 13:06:46 -0000      1.56
+++ src/daemon/common/commonSwarming.ml 25 Jan 2007 13:09:16 -0000      1.57
@@ -136,6 +136,10 @@
     mutable t_chunk_of_block : int array;
   }
 
+and uploader_map = {
+    mutable um_map : Bitv.t;
+    }
+
 and swarmer = {
     s_num : int;
     s_filename : string;
@@ -149,6 +153,7 @@
     mutable s_verified_bitmap : VerificationBitmap.t;
     mutable s_disk_allocated : Bitv.t;
     mutable s_availability : int array;
+    mutable s_availability_map : (client,uploader_map) Hashtbl.t;
     mutable s_nuploading : int array;
 (*    mutable s_last_seen : int array; *)
 
@@ -573,6 +578,7 @@
     s_blocks = [||];
     s_block_pos = [||];
     s_availability = [||];
+    s_availability_map = Hashtbl.create 0;
     s_nuploading = [||];
   }
 
@@ -613,6 +619,7 @@
       s_blocks = Array.create nblocks EmptyBlock ;
       s_block_pos = Array.create nblocks zero;
       s_availability = Array.create nblocks 0;
+      s_availability_map = Hashtbl.create 0;
       s_nuploading = Array.create nblocks 0;
 (*      s_last_seen = Array.create nblocks 0; *)
     }
@@ -741,6 +748,7 @@
   s.s_verified_bitmap <- VB.create nblocks VB.State_missing;
   s.s_block_pos <- Array.create nblocks zero;
   s.s_availability <- Array.create nblocks 0; (* not preserved ? *)
+  s.s_availability_map <- Hashtbl.create 1023;
   s.s_nuploading <- Array.create nblocks 0; (* not preserved ? *)
 (*  s.s_last_seen <- Array.create nblocks 0; *)
 
@@ -1711,15 +1719,26 @@
   let complete_blocks = ref [] in
   let partial_blocks = ref [] in
 
-  let incr_availability s i =
-    s.s_availability.(i) <- s.s_availability.(i) + 1 in
+  let uploaders_map = 
+    try
+      Hashtbl.find s.s_availability_map up.up_client
+    with Not_found ->
+      let map = {um_map = Bitv.create (Array.length s.s_blocks) false
+      } in
+      Hashtbl.add s.s_availability_map up.up_client map;
+      map
+  in
+  let map = uploaders_map.um_map in
+  (* we dont initialize the map with false for an exiting uploader,
+     cause the number of blocks should increase over time, not decrease.
+     should we? *)
 
   (match intervals with
    | AvailableIntervals intervals ->
        iter_intervals s (fun i block_begin block_end interval_begin 
interval_end ->
 (*              lprintf "iter_intervals %d %Ld-%Ld %Ld-%Ld\n"
                 i block_begin block_end interval_begin interval_end; *)
-         incr_availability s i;
+         Bitv.set map i true;
 
          match s.s_blocks.(i) with
         | CompleteBlock | VerifiedBlock -> ()
@@ -1734,7 +1753,7 @@
    | AvailableBitv bitmap ->
        Bitv.iteri_true (fun i ->
          List.iter (fun j ->
-           incr_availability s j;
+           Bitv.set map j true;
            complete_blocks := j :: !complete_blocks
          ) t.t_blocks_of_chunk.(i)
        ) bitmap
@@ -1746,6 +1765,14 @@
     t.t_last_seen.(i) <- BasicSocket.last_time ()
   ) !complete_blocks;
 
+  let availability = Array.create (Array.length s.s_blocks) 0 in
+  Hashtbl.iter (fun _ j ->
+    Bitv.iteri_true (fun i ->
+      availability.(i) <- availability.(i) + 1
+    ) j.um_map
+  ) s.s_availability_map;
+  s.s_availability <- availability;
+
   let complete_blocks = Array.of_list !complete_blocks in
   let partial_blocks = Array.of_list !partial_blocks in
   up.up_intervals <- intervals;
@@ -1835,18 +1862,8 @@
 
 let clear_uploader_intervals up =
   if up.up_declared then
-    let decr_availability s i =
-      if s.s_availability.(i) > 0 then
-       s.s_availability.(i) <- s.s_availability.(i) - 1 
-      else 
-       lprintf_nl "clear_uploader_intervals: some s_availability was about to 
become negative\n" in
-(*          lprintf "clean_uploader_chunks:\n"; *)
-    let t = up.up_t in
-    let s = t.t_s in
-    Array.iter (decr_availability s) up.up_complete_blocks;
     up.up_complete_blocks <- [||];
     up.up_ncomplete <- 0;
-    Array.iter (fun (b,_,_) -> decr_availability s b) up.up_partial_blocks;
     up.up_partial_blocks <- [||];
     up.up_npartial <- 0;
     clear_uploader_blocks up;
@@ -2129,6 +2146,7 @@
          match !!swarming_block_selection_algorithm with
          | 1 -> true
          | 2 -> verification_available && t.t_nverified_chunks < 2
+         | 3 -> false
          | _ -> assert false in
 
        let create_choice n b =
@@ -2330,10 +2348,79 @@
            (* Can't tell *)
            0 in
 
+       let compare_choices3 c1 c2 =
+         (* "RULES" *)
+         (* Avoid stepping on each other's feet *)
+         let cmp =
+           match choice_unselected_remaining c1,
+           choice_unselected_remaining c2 with
+           | 0L, 0L -> 0
+           | _, 0L -> 1
+           | 0L, _ -> -1
+           | _, _ -> 0 in
+         if cmp <> 0 then cmp else
+
+    (* avoid overly unbalanced situations *)
+    let cmp =
+      match choice_saturated c1, choice_saturated c2 with
+      | false, false -> 0
+      | false, true -> 1
+      | true, false -> -1
+      | true, true -> 0 in
+    if cmp <> 0 then cmp else
+
+    (* "WISHES" *)
+         (* Do what Master asked for *)
+    let cmp = compare (choice_user_priority c1)
+             (choice_user_priority c2) in
+         if cmp <> 0 then cmp else
+
+    (* "OPTIMIZATIONS" *)
+    (* Allways pick rarer choice, if at least one availability
+       is below mean_availability*)
+    let cmp =
+      if not need_to_complete_some_blocks_quickly &&
+      (mean_availability < 5 ||
+      choice_availability c1 <= mean_availability || 
+      choice_availability c2 <= mean_availability) then
+        compare (choice_availability c2)
+        (choice_availability c1)
+      else 0 in
+    if cmp <> 0 then cmp else
+  
+         (* try to quickly complete (and validate) chunks; 
+            if there's only one frontend, each chunk has only one
+            block, and looking at siblings make no sense *)
+         let cmp = 
+           if verification_available && several_frontends then 
+        compare (choice_other_remaining c2)
+        (choice_other_remaining c1)
+           else 0 in
+         if cmp <> 0 then cmp else
+
+         (* try to quickly complete blocks *)
+         let cmp = 
+           compare (choice_unselected_remaining c2)
+             (choice_unselected_remaining c1) in
+         if cmp <> 0 then cmp else
+
+         (* pick blocks that won't require allocating more disk space *)
+         let cmp =
+           match choice_preallocated c1, choice_preallocated c2 with
+           | true, false -> 1
+           | false, true -> -1
+           | _ -> 0 in
+         if cmp <> 0 then cmp else
+
+         (* "DEFAULT" *)
+           (* Can't tell *)
+           0 in
+
        let compare_choices =
          match !!swarming_block_selection_algorithm with
          | 1 -> compare_choices1
          | 2 -> compare_choices2
+         | 3 -> compare_choices3
          | _ -> assert false in
 
        (* compare a new chunk against a list of best choices numbers (and a




reply via email to

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