Changeset 3678aa1


Ignore:
Timestamp:
Nov 1, 2010 2:35:01 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ddc86b54
Parents:
8d13bcb
Message:
  • i2psnark:
    • Limit number of parallel requests of a single piece when in the end game
    • Shorten and weight the speed tracker so the display is more reflective of current speed
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/Peer.java

    r8d13bcb r3678aa1  
    5757  final static long CHECK_PERIOD = PeerCoordinator.CHECK_PERIOD; // 40 seconds
    5858  final static int RATE_DEPTH = PeerCoordinator.RATE_DEPTH; // make following arrays RATE_DEPTH long
    59   private long uploaded_old[] = {-1,-1,-1,-1,-1,-1};
    60   private long downloaded_old[] = {-1,-1,-1,-1,-1,-1};
     59  private long uploaded_old[] = {-1,-1,-1};
     60  private long downloaded_old[] = {-1,-1,-1};
    6161
    6262  /**
     
    405405
    406406  /**
     407   * Are we currently requesting the piece?
     408   * @since 0.8.1
     409   */
     410  boolean isRequesting(int p) {
     411    PeerState s = state;
     412    return s != null && s.isRequesting(p);
     413  }
     414
     415  /**
    407416   * Update the request queue.
    408417   * Call after adding wanted pieces.
     
    573582  public void setRateHistory(long up, long down)
    574583  {
    575     setRate(up, uploaded_old);
    576     setRate(down, downloaded_old);
    577   }
    578 
    579   private void setRate(long val, long array[])
    580   {
    581     synchronized(array) {
    582       for (int i = RATE_DEPTH-1; i > 0; i--)
    583         array[i] = array[i-1];
    584       array[0] = val;
    585     }
     584    PeerCoordinator.setRate(up, uploaded_old);
     585    PeerCoordinator.setRate(down, downloaded_old);
    586586  }
    587587
     
    591591  public long getUploadRate()
    592592  {
    593     return getRate(uploaded_old);
     593    return PeerCoordinator.getRate(uploaded_old);
    594594  }
    595595
    596596  public long getDownloadRate()
    597597  {
    598     return getRate(downloaded_old);
    599   }
    600 
    601   private long getRate(long array[])
    602   {
    603     long rate = 0;
    604     int i = 0;
    605     synchronized(array) {
    606       for ( ; i < RATE_DEPTH; i++){
    607         if (array[i] < 0)
    608             break;
    609         rate += array[i];
    610       }
    611     }
    612     if (i == 0)
    613         return 0;
    614     return rate / (i * CHECK_PERIOD / 1000);
    615   }
    616 
     598    return PeerCoordinator.getRate(downloaded_old);
     599  }
    617600}
  • apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java

    r8d13bcb r3678aa1  
    5858  private long uploaded;
    5959  private long downloaded;
    60   final static int RATE_DEPTH = 6; // make following arrays RATE_DEPTH long
    61   private long uploaded_old[] = {-1,-1,-1,-1,-1,-1};
    62   private long downloaded_old[] = {-1,-1,-1,-1,-1,-1};
     60  final static int RATE_DEPTH = 3; // make following arrays RATE_DEPTH long
     61  private long uploaded_old[] = {-1,-1,-1};
     62  private long downloaded_old[] = {-1,-1,-1};
    6363
    6464  // synchronize on this when changing peers or downloaders
     
    194194  }
    195195
    196   private static void setRate(long val, long array[])
     196  static void setRate(long val, long array[])
    197197  {
    198198    synchronized(array) {
     
    225225  }
    226226
    227   private long getRate(long array[])
     227  static long getRate(long array[])
    228228  {
    229229    long rate = 0;
    230230    int i = 0;
     231    int factor = 0;
    231232    synchronized(array) {
    232233      for ( ; i < RATE_DEPTH; i++) {
    233234        if (array[i] < 0)
    234235            break;
    235         rate += array[i];
     236        int f = RATE_DEPTH - i;
     237        rate += array[i] * f;
     238        factor += f;
    236239      }
    237240    }
    238241    if (i == 0)
    239242        return 0;
    240     return rate / (i * CHECK_PERIOD / 1000);
     243    return rate / (factor * i * CHECK_PERIOD / 1000);
    241244  }
    242245
     
    511514
    512515  /**
     516   *  Max number of peers to get a piece from when in end game
     517   *  @since 0.8.1
     518   */
     519  private static final int MAX_PARALLEL_REQUESTS = 4;
     520
     521  /**
    513522   * Returns one of pieces in the given BitField that is still wanted or
    514523   * -1 if none of the given pieces are wanted.
     
    552561                return -1;  // nothing to request and not in end game
    553562            // let's not all get on the same piece
     563            // Even better would be to sort by number of requests
    554564            Collections.shuffle(requested, _random);
    555565            Iterator<Piece> it2 = requested.iterator();
     
    557567              {
    558568                Piece p = it2.next();
    559                 if (havePieces.get(p.getId()))
    560                   {
     569                if (havePieces.get(p.getId())) {
     570                    // limit number of parallel requests
     571                    int requestedCount = 0;
     572                    synchronized(peers) {
     573                        for (Peer pr : peers) {
     574                            if (pr.isRequesting(p.getId())) {
     575                                if (pr.equals(peer)) {
     576                                    // don't give it to him again
     577                                    requestedCount = MAX_PARALLEL_REQUESTS;
     578                                    break;
     579                                }
     580                                if (++requestedCount >= MAX_PARALLEL_REQUESTS)
     581                                    break;
     582                            }
     583                        }
     584                    }
     585                    if (requestedCount >= MAX_PARALLEL_REQUESTS)
     586                        continue;
    561587                    piece = p;
    562                   }
     588                }
    563589              }
    564590            if (piece == null) {
     
    569595                return -1; //If we still can't find a piece we want, so be it.
    570596            } else {
    571                 // Should be a lot smarter here - limit # of parallel attempts and
     597                // Should be a lot smarter here -
    572598                // share blocks rather than starting from 0 with each peer.
    573599                // This is where the flaws of the snark data model are really exposed.
  • apps/i2psnark/java/src/org/klomp/snark/PeerState.java

    r8d13bcb r3678aa1  
    469469              }
    470470          }
     471  }
     472
     473  /**
     474   * Are we currently requesting the piece?
     475   * @since 0.8.1
     476   */
     477  synchronized boolean isRequesting(int piece) {
     478      for (Request req : outstandingRequests) {
     479          if (req.piece == piece)
     480              return true;
     481      }
     482      return false;
    471483  }
    472484
  • history.txt

    r8d13bcb r3678aa1  
     12010-11-01 zzz
     2    * ClientConnectionRunner: Add synch to fix race causing AIOOBE
     3                              (http://forum.i2p/viewtopic.php?t=5061)
     4    * configlogging.jsp: Parse log limit with current locale
     5                (ticket #118)
     6    * i2psnark:
     7      - Limit number of parallel requests of a single piece when in the end game
     8      - Shorten and weight the speed tracker so the display is more
     9        reflective of current speed
     10    * logs.jsp: Add message if wrapper log not found
     11                (ticket #103)
     12
    1132010-10-30 zzz
    214    * i2psnark:
  • router/java/src/net/i2p/router/RouterVersion.java

    r8d13bcb r3678aa1  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 6;
     21    public final static long BUILD = 7;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.