I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Unverified Commit 6b185942 authored by zzz's avatar zzz
Browse files

i2psnark: Throttle torrent startup to prevent OOMs

for a large number torrents
ref: http://zzz.i2p/topics/3475
parent 4af21221
No related branches found
Tags i2p-0.9.49
No related merge requests found
......@@ -2899,6 +2899,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("DirMon found: " + DataHelper.toString(foundNames) + " existing: " + DataHelper.toString(existingNames));
// lets find new ones first...
int count = 0;
for (String name : foundNames) {
if (existingNames.contains(name)) {
// already known. noop
......@@ -2926,6 +2927,10 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
disableTorrentFile(name);
rv = false;
}
if (shouldStart && (count++ & 0x0f) == 15) {
// try to prevent OOMs at startup
try { Thread.sleep(250); } catch (InterruptedException ie) {}
}
}
}
// Don't remove magnet torrents that don't have a torrent file yet
......@@ -3105,21 +3110,19 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
}
/**
* If not connected, thread it, otherwise inline
* Always thread it
* @since 0.9.1
*/
public void startAllTorrents() {
if (_util.connected()) {
startAll();
} else {
if (!_util.connected()) {
addMessage(_t("Opening the I2P tunnel and starting all torrents."));
for (Snark snark : _snarks.values()) {
// mark it for the UI
snark.setStarting();
}
(new I2PAppThread(new ThreadedStarter(null), "TorrentStarterAll", true)).start();
try { Thread.sleep(200); } catch (InterruptedException ie) {}
}
(new I2PAppThread(new ThreadedStarter(null), "TorrentStarterAll", true)).start();
try { Thread.sleep(200); } catch (InterruptedException ie) {}
}
/**
......@@ -3149,6 +3152,7 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
* @since 0.9.1
*/
private void startAll() {
int count = 0;
for (Snark snark : _snarks.values()) {
if (snark.isStopped()) {
try {
......@@ -3156,6 +3160,10 @@ public class SnarkManager implements CompleteListener, ClientApp, DisconnectList
} catch (RuntimeException re) {
// Snark.fatal() will log and call fatal() here for user message before throwing
}
if ((count++ & 0x0f) == 15) {
// try to prevent OOMs
try { Thread.sleep(250); } catch (InterruptedException ie) {}
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment