Changeset 4c1050b


Ignore:
Timestamp:
Jan 12, 2011 1:19:20 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
65c61864
Parents:
dfcb81c
Message:
  • Router:
    • Add new RandomIterator?, use in UDP, peer selector, profile organizer
    • Add a stat to monitor peer selector run time
Location:
router/java/src/net/i2p/router
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

    rdfcb81c r4c1050b  
    1212import java.util.Collections;
    1313import java.util.HashSet;
     14import java.util.Iterator;
    1415import java.util.List;
    1516import java.util.Set;
     
    2021import net.i2p.router.RouterContext;
    2122import net.i2p.router.peermanager.PeerProfile;
     23import net.i2p.router.util.RandomIterator;
    2224import net.i2p.stat.Rate;
    2325import net.i2p.util.Log;
     
    7577            peersToIgnore = new HashSet(1);
    7678        peersToIgnore.add(_context.routerHash());
     79        // TODO this is very slow
    7780        FloodfillSelectionCollector matches = new FloodfillSelectionCollector(key, peersToIgnore, maxNumRouters);
    7881        if (kbuckets == null) return new ArrayList();
     
    105108    private List<Hash> selectFloodfillParticipants(Set<Hash> toIgnore, KBucketSet kbuckets) {
    106109        if (kbuckets == null) return Collections.EMPTY_LIST;
     110        // TODO this is very slow - use profile getPeersByCapability('f') instead
     111        _context.statManager().addRateData("netDb.newFSC", 0, 0);
    107112        FloodfillSelectionCollector matches = new FloodfillSelectionCollector(null, toIgnore, 0);
    108113        kbuckets.getAll(matches);
     
    321326         */
    322327        public List<Hash> get(int howMany, boolean preferConnected) {
    323             Collections.shuffle(_floodfillMatches, _context.random());
    324328            List<Hash> rv = new ArrayList(howMany);
    325329            List<Hash> badff = new ArrayList(howMany);
     
    330334            // Let's say published in last 3h and no failed sends in last 30m
    331335            // (Forever shitlisted ones are excluded in add() above)
    332             for (int i = 0; found < howMany && i < _floodfillMatches.size(); i++) {
    333                 Hash entry = (Hash) _floodfillMatches.get(i);
     336            for (Iterator<Hash> iter = new RandomIterator(_floodfillMatches); (found < howMany) && iter.hasNext(); ) {
     337                Hash entry = iter.next();
    334338                RouterInfo info = _context.netDb().lookupRouterInfoLocally(entry);
    335339                if (info != null && now - info.getPublished() > 3*60*60*1000) {
     
    392396            // return non-ff
    393397            peersToIgnore.addAll(selectFloodfillParticipants(peersToIgnore, kbuckets));
     398            // TODO this is very slow
    394399            FloodfillSelectionCollector matches = new FloodfillSelectionCollector(rkey, peersToIgnore, maxNumRouters);
    395400            kbuckets.getAll(matches);
  • router/java/src/net/i2p/router/networkdb/kademlia/KBucketSet.java

    rdfcb81c r4c1050b  
    4343        _log = context.logManager().getLog(KBucketSet.class);
    4444        createBuckets();
     45        context.statManager().createRateStat("netDb.KBSGetAllTime", "Time to add all Hashes to the Collector", "NetworkDatabase", new long[] { 60*60*1000 });
    4546    }
    4647   
     
    100101   
    101102    public void getAll(SelectionCollector collector) {
     103        long start = _context.clock().now();
    102104        for (int i = 0; i < _buckets.length; i++)
    103105            _buckets[i].getEntries(collector);
     106        _context.statManager().addRateData("netDb.KBSGetAllTime", _context.clock().now() - start, 0);
    104107    }
    105108   
  • router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java

    rdfcb81c r4c1050b  
    2929import net.i2p.router.RouterContext;
    3030import net.i2p.router.tunnel.pool.TunnelPeerSelector;
     31import net.i2p.router.util.RandomIterator;
    3132import net.i2p.stat.Rate;
    3233import net.i2p.stat.RateStat;
     
    10441045        locked_selectPeers(peers, howMany, toExclude, matches, 0);
    10451046    }
     1047
    10461048    private void locked_selectPeers(Map<Hash, PeerProfile> peers, int howMany, Set<Hash> toExclude, Set<Hash> matches, int mask) {
    1047         List all = new ArrayList(peers.keySet());
    1048         if (toExclude != null)
    1049             all.removeAll(toExclude);
    1050        
    1051         all.removeAll(matches);
    1052         all.remove(_us);
    1053         Collections.shuffle(all, _random);
     1049        List<Hash> all = new ArrayList(peers.keySet());
    10541050        Set<Integer> IPSet = new HashSet(8);
    1055         for (int i = 0; (matches.size() < howMany) && (i < all.size()); i++) {
    1056             Hash peer = (Hash)all.get(i);
     1051        // use RandomIterator to avoid shuffling the whole thing
     1052        for (Iterator<Hash> iter = new RandomIterator(all); (matches.size() < howMany) && iter.hasNext(); ) {
     1053            Hash peer = iter.next();
     1054            if (toExclude != null && toExclude.contains(peer))
     1055                continue;
     1056            if (matches.contains(peer))
     1057                continue;
     1058            if (_us.equals(peer))
     1059                continue;
    10571060            boolean ok = isSelectable(peer);
    10581061            if (ok) {
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    rdfcb81c r4c1050b  
    3535import net.i2p.router.transport.TransportBid;
    3636import net.i2p.router.transport.TransportImpl;
     37import net.i2p.router.util.RandomIterator;
    3738import net.i2p.util.ConcurrentHashSet;
    3839import net.i2p.util.Log;
     
    23272328    PeerState pickTestPeer(RemoteHostId dontInclude) {
    23282329        List<PeerState> peers = new ArrayList(_peersByIdent.values());
    2329         Collections.shuffle(peers, _context.random());
    2330         for (int i = 0; i < peers.size(); i++) {
    2331             PeerState peer = peers.get(i);
     2330        for (Iterator<PeerState> iter = new RandomIterator(peers); iter.hasNext(); ) {
     2331            PeerState peer = iter.next();
    23322332            if ( (dontInclude != null) && (dontInclude.equals(peer.getRemoteHostId())) )
    23332333                continue;
Note: See TracChangeset for help on using the changeset viewer.