Changeset 7ed855b


Ignore:
Timestamp:
Jan 9, 2015 5:03:33 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
45b3e44c
Parents:
f08552c
Message:

NetDB: Publish RI faster when costs change (ticket #1437)
PLRIJ interval was 37-50 minutes. Reduce that by 4x,
but for 3 out of 4 times, only publish if something changes,
including cost. 4th time, always publish, as before.
This will hopefully reduce routers getting slammed to
conn limits on a transport.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    rf08552c r7ed855b  
     12015-01-09 zzz
     2 * NetDB: Publish RI faster when costs change (ticket #1437)
     3
     42015-01-08 zzz
     5 * Console, i2ptunnel, proxy: Renaming of various things to "hidden services"
     6
    172015-01-07 zzz
    28 * ClientAppConfig: Start i2ptunnel sooner (ticket #1162)
    39 * NetDB: Possible fixes for reseed completion not recognized (ticket #1384)
    4  * Router: Add startup/shutdown state machine
     10 * Router:
     11   - Add startup/shutdown state machine
     12   - Don't reset uptime after a soft restart
    513 * Startup: Accept tunnels after 10 minutes instead of 20 (ticket #1152)
    6  * Tunnels: Cleanup, catch more cases of zero-hop configuration
     14 * Tunnels:
     15   - Cleanup, catch more cases of zero-hop configuration
     16   - Temporarily increase exploratory tunnel quantity at startup,
     17     so that netdb refresh will work better
    718
    8192015-01-05 zzz
  • router/java/src/net/i2p/router/RouterVersion.java

    rf08552c r7ed855b  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 9;
     21    public final static long BUILD = 10;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/networkdb/PublishLocalRouterInfoJob.java

    rf08552c r7ed855b  
    99 */
    1010
     11import java.io.Serializable;
     12import java.util.ArrayList;
     13import java.util.Collections;
     14import java.util.Comparator;
    1115import java.util.Date;
     16import java.util.List;
    1217import java.util.Properties;
     18import java.util.concurrent.atomic.AtomicInteger;
    1319
    1420import net.i2p.data.DataFormatException;
     21import net.i2p.data.router.RouterAddress;
    1522import net.i2p.data.router.RouterInfo;
    1623import net.i2p.data.SigningPrivateKey;
     
    3138    /**
    3239     *  Don't store if somebody else stored it recently.
     40     *  Must be less than PUBLISH_DELAY * 3 / 16 (see getDelay())
    3341     */
    34     private static final long MIN_PUBLISH_DELAY = 25*60*1000;
     42    private static final long MIN_PUBLISH_DELAY = 9*60*1000;
    3543
    3644    /**
     
    3947     *  Too long and the floodfill will drop us - timeout is 60 minutes.
    4048     */
    41     private static final long PUBLISH_DELAY = MIN_PUBLISH_DELAY * 2;
     49    private static final long PUBLISH_DELAY = 52*60*1000;
    4250
    4351    /** this needs to be long enough to give us time to start up,
     
    4856     */
    4957    private static final long FIRST_TIME_DELAY = 90*1000;
    50     boolean _notFirstTime;
     58    private volatile boolean _notFirstTime;
     59    private final AtomicInteger _runCount = new AtomicInteger();
    5160   
    5261    public PublishLocalRouterInfoJob(RouterContext ctx) {
     
    5665   
    5766    public String getName() { return "Publish Local Router Info"; }
     67
    5868    public void runJob() {
    5969        long last = getContext().netDb().getLastRouterInfoPublishTime();
     
    6474            return;
    6575        }
    66         RouterInfo ri = new RouterInfo(getContext().router().getRouterInfo());
     76        RouterInfo oldRI = getContext().router().getRouterInfo();
    6777        if (_log.shouldLog(Log.DEBUG))
    68             _log.debug("Old routerInfo contains " + ri.getAddresses().size()
    69                        + " addresses and " + ri.getOptionsMap().size() + " options");
    70         Properties stats = getContext().statPublisher().publishStatistics();
    71         stats.setProperty(RouterInfo.PROP_NETWORK_ID, ""+Router.NETWORK_ID);
     78            _log.debug("Old routerInfo contains " + oldRI.getAddresses().size()
     79                       + " addresses and " + oldRI.getOptionsMap().size() + " options");
    7280        try {
     81            List<RouterAddress> oldAddrs = new ArrayList(oldRI.getAddresses());
     82            List<RouterAddress> newAddrs = getContext().commSystem().createAddresses();
     83            int count = _runCount.incrementAndGet();
     84            if (_notFirstTime && (count % 4) != 0 && oldAddrs.size() == newAddrs.size()) {
     85                // 3 times out of 4, we don't republish if everything is the same...
     86                // If something changed, including the cost, then publish,
     87                // otherwise don't.
     88                boolean different = false;
     89                Comparator<RouterAddress> comp = new AddrComparator();
     90                Collections.sort(oldAddrs, comp);
     91                Collections.sort(newAddrs, comp);
     92                for (int i = 0; i < oldAddrs.size(); i++) {
     93                    // deepEquals() includes cost
     94                    if (!oldAddrs.get(i).deepEquals(newAddrs.get(i))) {
     95                        different = true;
     96                        break;
     97                    }
     98                }
     99                if (!different) {
     100                    if (_log.shouldLog(Log.INFO))
     101                        _log.info("Not republishing early because costs are the same");
     102                    requeue(getDelay());
     103                    return;
     104                }
     105                if (_log.shouldLog(Log.INFO))
     106                    _log.info("Republishing early because addresses or costs have changed - old:\n" +
     107                              oldAddrs + "\nnew:\n" + newAddrs);
     108            }
     109            RouterInfo ri = new RouterInfo(oldRI);
    73110            ri.setPublished(getContext().clock().now());
     111            Properties stats = getContext().statPublisher().publishStatistics();
     112            stats.setProperty(RouterInfo.PROP_NETWORK_ID, ""+Router.NETWORK_ID);
    74113            ri.setOptions(stats);
    75             ri.setAddresses(getContext().commSystem().createAddresses());
     114            ri.setAddresses(newAddrs);
    76115
    77116            getContext().router().addCapabilities(ri);
     
    99138        }
    100139        if (_notFirstTime) {
    101             long delay = getDelay();
    102             requeue(delay);
     140            requeue(getDelay());
    103141        } else {
    104142            requeue(FIRST_TIME_DELAY);
     
    108146
    109147    private long getDelay() {
    110         return (PUBLISH_DELAY * 3 / 4) + getContext().random().nextLong(PUBLISH_DELAY / 4);
     148        long rv = (PUBLISH_DELAY * 3 / 4) + getContext().random().nextLong(PUBLISH_DELAY / 4);
     149        // run 4x as often as usual publish time (see above)
     150        rv /= 4;
     151        return rv;
     152    }
     153
     154    /**
     155     *  Arbitrary sort so we can attempt to compare costs between two RIs to see if they have changed
     156     *
     157     *  @since 0.9.18
     158     */
     159    private static class AddrComparator implements Comparator<RouterAddress>, Serializable {
     160        public int compare(RouterAddress l, RouterAddress r) {
     161            int c = l.getTransportStyle().compareTo(r.getTransportStyle());
     162            if (c != 0)
     163                return c;
     164            String lh = l.getHost();
     165            String rh = r.getHost();
     166            if (lh == null)
     167                return rh == null ? 0 : -1;
     168            if (rh == null)
     169                return 1;
     170            return lh.compareTo(rh);
     171        }
    111172    }
    112173}
Note: See TracChangeset for help on using the changeset viewer.