From dd4d12f287cc4612473a38d67837639ff924c44a Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 10 Oct 2015 14:02:48 +0000 Subject: [PATCH] i2psnark: Increase max piece size to 16 MB, max files to 999, close files faster based on file count (tickets #1626, #1671) Remove dup synchs --- .../src/org/klomp/snark/PeerCheckerTask.java | 18 ++++++++++++- .../src/org/klomp/snark/SnarkManager.java | 2 +- .../java/src/org/klomp/snark/Storage.java | 26 ++++++++++--------- history.txt | 9 +++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerCheckerTask.java b/apps/i2psnark/java/src/org/klomp/snark/PeerCheckerTask.java index 430f6c7ae6..c2abf66609 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerCheckerTask.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerCheckerTask.java @@ -267,7 +267,23 @@ class PeerCheckerTask implements Runnable // close out unused files, but we don't need to do it every time Storage storage = coordinator.getStorage(); - if (storage != null && (_runCount % 4) == 0) { + if (storage != null) { + // The more files a torrent has, the more often we call the cleaner, + // to keep from running out of FDs + int files = storage.getFileCount(); + int skip; + if (files == 1) + skip = 6; + else if (files <= 4) + skip = 4; + else if (files <= 20) + skip = 3; + else if (files <= 50) + skip = 2; + else + skip = 1; + + if ((_runCount % skip) == 0) storage.cleanRAFs(); } diff --git a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java index bcb4fa34c2..98d0ee2c0b 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java +++ b/apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java @@ -1092,7 +1092,7 @@ public class SnarkManager implements CompleteListener { } /** hardcoded for sanity. perhaps this should be customizable, for people who increase their ulimit, etc. */ - public static final int MAX_FILES_PER_TORRENT = 512; + public static final int MAX_FILES_PER_TORRENT = 999; /** * Set of canonical .torrent filenames that we are dealing with. diff --git a/apps/i2psnark/java/src/org/klomp/snark/Storage.java b/apps/i2psnark/java/src/org/klomp/snark/Storage.java index 62cb1aa45d..3f16823187 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Storage.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Storage.java @@ -78,7 +78,7 @@ public class Storage implements Closeable /** The default piece size. */ private static final int DEFAULT_PIECE_SIZE = 256*1024; /** bigger than this will be rejected */ - public static final int MAX_PIECE_SIZE = 8*1024*1024; + public static final int MAX_PIECE_SIZE = 16*1024*1024; /** The maximum number of pieces in a torrent. */ public static final int MAX_PIECES = 10*1024; public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES; @@ -819,6 +819,14 @@ public class Storage implements Closeable return rv; } + /** + * Does not include directories. + * @since 0.9.23 + */ + public int getFileCount() { + return _torrentFiles.size(); + } + /** * Includes the base for a multi-file torrent. * Sorted bottom-up for easy deletion. @@ -958,11 +966,9 @@ public class Storage implements Closeable pieceEnd += length; while (fileEnd <= pieceEnd) { TorrentFile tf = _torrentFiles.get(file); - synchronized(tf) { - try { - tf.closeRAF(); - } catch (IOException ioe) {} - } + try { + tf.closeRAF(); + } catch (IOException ioe) {} if (++file >= _torrentFiles.size()) break; fileEnd += _torrentFiles.get(file).length; @@ -1035,9 +1041,7 @@ public class Storage implements Closeable for (TorrentFile tf : _torrentFiles) { try { - synchronized(tf) { tf.closeRAF(); - } } catch (IOException ioe) { _log.error("Error closing " + tf, ioe); // gobble gobble @@ -1262,17 +1266,15 @@ public class Storage implements Closeable return length; } - private static final long RAFCloseDelay = 4*60*1000; + private static final long RAF_CLOSE_DELAY = 4*60*1000; /** * Close unused RAFs - call periodically */ public void cleanRAFs() { - long cutoff = System.currentTimeMillis() - RAFCloseDelay; + long cutoff = System.currentTimeMillis() - RAF_CLOSE_DELAY; for (TorrentFile tf : _torrentFiles) { - synchronized(tf) { tf.closeRAF(cutoff); - } } } diff --git a/history.txt b/history.txt index bd4cde9e3b..0dccbc1306 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,9 @@ +2015-10-10 zzz + * i2psnark: Increase max piece size to 16 MB, max files to 999, + close files faster based on file count (tickets #1626, #1671) + * JobQueue: Only adjust timing for negative clock shifts + * NamingServices: Add support for lookups prefixed with "www." + 2015-10-08 zzz * SimpleTimer2: Additional fix for uncaught IllegalStateException affecting streaming timers (ticket #1672) @@ -30,6 +36,9 @@ 2015-09-25 dg * Rename _() for translation to _t() for Java 9 compatibility (ticket #1456) +2015-09-24 zzz + - Rename bad .torrent files instead of deleting them + 2015-09-20 dg * /configreseed: Add 'Reset URL list' button for revert to default hosts (ticket #1554, thanks dzirtt@gmail.com) diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index ea17ad55f3..e1f87e077d 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 15; + public final static long BUILD = 16; /** for example "-test" */ public final static String EXTRA = "";