[freenet-dev] New config option?

Juiceman juiceman69 at gmail.com
Wed May 23 03:15:52 UTC 2007


I know we had a brief discussion on -tech where this was decided to be
unnecessary, but I coded it for myself and thought I would throw it
out here so you guys can see what I was trying to accomplish.

This allows me to only use 5% of my 18 gig datastore for cache instead
of 9 gigs like the default.  This is an expert config option and it
defaults to 50% so users would have the same ratio unless they enabled
expert and changed the value.  Even then they couldn't reduce their
specialized store, only the cache.



--- Node.java	(revision 13327)
+++ Node.java	(working copy)
@@ -268,6 +268,8 @@
 	static final int sizePerKey = CHKBlock.DATA_LENGTH +
CHKBlock.TOTAL_HEADERS_LENGTH +
 		DSAPublicKey.PADDED_SIZE + SSKBlock.DATA_LENGTH +
SSKBlock.TOTAL_HEADERS_LENGTH;
 	
+	//Percent of the datastore to use for cache of popular data.
+	private int cachePercent;
 	/** The maximum number of keys stored in each of the datastores,
cache and store combined. */
 	private long maxTotalKeys;
 	private long maxCacheKeys;
@@ -1069,6 +1071,29 @@
 			
 		});
 		
+		nodeConfig.register("cachePercent", "50", sortOrder++, true, false,
"Node.cachePercentStore", "Node.cachePercenStoretLong",
+				new IntCallback() {
+				
+					public int get() {
+						return cachePercent;
+					}
+					
+					public void set(int val) throws InvalidConfigValueException {
+						if((val < 5) || (val > 50))
+							throw new InvalidConfigValueException("Percent must be between
5 and 50");
+						cachePercent = val;
+					}
+		
+	});
+		
+		cachePercent = nodeConfig.getInt("cachePercent");
+		
+		if((cachePercent < 5) || (cachePercent > 50)){  //Make sure the
user didn't bork the config file.
+			System.out.println("Found cachePercent lower then 5 or greater
than 50: " + cachePercent);
+			cachePercent = 50;   // 50 is a good safe number, it is the default.
+			System.out.println("Reset cachePercent to " + cachePercent);
+		}
+		
 		nodeConfig.register("storeSize", "1G", sortOrder++, false, true,
"Node.storeSize", "Node.storeSizeLong",
 				new LongCallback() {

@@ -1077,7 +1102,7 @@
 					}

 					public void set(long storeSize) throws InvalidConfigValueException {
-						if((storeSize < 0) || (storeSize < (32 * 1024 * 1024)))
+						if((storeSize < 0) || (storeSize < (32 * 1024 * 1024)))  //
totally arbitrary minimum!
 							throw new InvalidConfigValueException(l10n("invalidStoreSize"));
 						long newMaxStoreKeys = storeSize / sizePerKey;
 						if(newMaxStoreKeys == maxTotalKeys) return;
@@ -1085,8 +1110,8 @@
 						synchronized(Node.this) {
 							maxTotalDatastoreSize = storeSize;
 							maxTotalKeys = newMaxStoreKeys;
-							maxStoreKeys = maxTotalKeys / 2;
-							maxCacheKeys = maxTotalKeys - maxStoreKeys;
+							maxCacheKeys = ((maxTotalKeys * cachePercent) / 100);
+							maxStoreKeys = maxTotalKeys - maxCacheKeys;
 						}
 						try {
 							chkDatastore.setMaxKeys(maxStoreKeys, storeForceBigShrinks);
@@ -1133,10 +1158,10 @@
 			String msg = "Could not find or create datastore directory";
 			throw new NodeInitException(EXIT_STORE_OTHER, msg);
 		}
-
-		maxStoreKeys = maxTotalKeys / 2;
-		maxCacheKeys = maxTotalKeys - maxStoreKeys;
 		
+		maxCacheKeys = ((maxTotalKeys * cachePercent) / 100);
+		maxStoreKeys = maxTotalKeys - maxCacheKeys;
+		
 		// Setup datastores
 		
 		// First, global settings





-- 
I may disagree with what you have to say, but I shall defend, to the
death, your right to say it. - Voltaire
Those who would give up Liberty, to purchase temporary Safety, deserve
neither Liberty nor Safety. - Ben Franklin



More information about the Devl mailing list