Changeset 890ad25


Ignore:
Timestamp:
Jan 30, 2017 10:05:43 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
82d812c
Parents:
7cb5dab
Message:

Router: Run shutdown tasks in parallel,
increase max time for shutdown tasks (ticket #1893)
i2psnark: Remove most delay between announces at shutdown

Files:
2 edited

Legend:

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

    r7cb5dab r890ad25  
    4343import net.i2p.util.SimpleTimer;
    4444import net.i2p.util.SimpleTimer2;
     45import net.i2p.util.SystemVersion;
    4546import net.i2p.util.Translate;
    4647
     
    303304     */
    304305    public void stop() {
     306        if (_log.shouldWarn())
     307            _log.warn("Snark stop() begin", new Exception("I did it"));
    305308        if (_umgr != null && _uhandler != null) {
    306309            //_uhandler.shutdown();
     
    313316        _idleChecker.cancel();
    314317        stopAllTorrents(true);
     318        if (_log.shouldWarn())
     319            _log.warn("Snark stop() end");
    315320    }
    316321   
     
    25812586                // Throttle since every unannounce is now threaded.
    25822587                // How to do this without creating a ton of threads?
    2583                 try { Thread.sleep(20); } catch (InterruptedException ie) {}
     2588                if (count % 8 == 0) {
     2589                    try { Thread.sleep(20); } catch (InterruptedException ie) {}
     2590                }
    25842591            }
    25852592        }
     
    25942601                addMessage(_t("Closing I2P tunnel after notifying trackers."));
    25952602                if (finalShutdown) {
    2596                     try { Thread.sleep(5*1000); } catch (InterruptedException ie) {}
     2603                    long toWait = 5*1000;
     2604                    if (SystemVersion.isARM())
     2605                        toWait *= 2;
     2606                    try { Thread.sleep(toWait); } catch (InterruptedException ie) {}
    25972607                }
     2608                _util.disconnect();
    25982609            } else {
    25992610                _util.disconnect();
  • router/java/src/net/i2p/router/Router.java

    r7cb5dab r890ad25  
    1414import java.util.Collection;
    1515import java.util.Collections;
     16import java.util.LinkedList;
    1617import java.util.List;
    1718import java.util.Map;
     
    122123    public static final String UPDATE_FILE = "i2pupdate.zip";
    123124       
     125    private static final int SHUTDOWN_WAIT_SECS = 60;
     126
    124127    private static final String originalTimeZoneID;
    125128    static {
     
    956959                             _context.bandwidthLimiter().getOutboundKBytesPerSecond());
    957960        bwLim = (int)(bwLim * getSharePercentage());
    958         if (_log.shouldLog(Log.INFO))
    959             _log.info("Adding capabilities w/ bw limit @ " + bwLim, new Exception("caps"));
    960961       
    961962        String force = _context.getProperty(PROP_FORCE_BWCLASS);
     
    12111212        // Run the shutdown hooks first in case they want to send some goodbye messages
    12121213        // Maybe we need a delay after this too?
     1214        LinkedList<Thread> tasks = new LinkedList<Thread>();
    12131215        for (Runnable task : _context.getShutdownTasks()) {
    12141216            //System.err.println("Running shutdown task " + task.getClass());
     
    12201222                t.setDaemon(true);
    12211223                t.start();
    1222                 try {
    1223                     t.join(10*1000);
    1224                 } catch (InterruptedException ie) {}
    1225                 if (t.isAlive())
    1226                     _log.logAlways(Log.WARN, "Shutdown task took more than 10 seconds to run: " + task.getClass());
     1224                tasks.add(t);
    12271225            } catch (Throwable t) {
    12281226                _log.log(Log.CRIT, "Error running shutdown task", t);
     1227            }
     1228        }
     1229        long waitSecs = SHUTDOWN_WAIT_SECS;
     1230        if (SystemVersion.isARM())
     1231            waitSecs *= 2;
     1232        final long maxWait = System.currentTimeMillis() + (waitSecs *1000);
     1233        Thread th;
     1234        while ((th = tasks.poll()) != null) {
     1235            long toWait = maxWait - System.currentTimeMillis();
     1236            if (toWait <= 0) {
     1237                _log.logAlways(Log.WARN, "Shutdown tasks took more than " + waitSecs + " seconds to run");
     1238                tasks.clear();
     1239                break;
     1240            }
     1241            try {
     1242                th.join(toWait);
     1243            } catch (InterruptedException ie) {}
     1244            if (th.isAlive()) {
     1245                _log.logAlways(Log.WARN, "Shutdown task took more than " + waitSecs + " seconds to run: " + th.getName());
     1246                tasks.clear();
     1247                break;
     1248            } else if (_log.shouldInfo()) {
     1249                _log.info("Shutdown task complete: " + th.getName());
    12291250            }
    12301251        }
Note: See TracChangeset for help on using the changeset viewer.