Author: mrogers
Date: 2006-11-16 16:45:33 +0000 (Thu, 16 Nov 2006)
New Revision: 10948

Modified:
   trunk/apps/load-balancing-sims/phase7/sim/Node.java
   trunk/apps/load-balancing-sims/phase7/sim/generators/SimplePublisher.java
   trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java
Log:
Added public key store; load tests now use a mixture of SSKs and CHKs

Modified: trunk/apps/load-balancing-sims/phase7/sim/Node.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-16 16:45:01 UTC 
(rev 10947)
+++ trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-16 16:45:33 UTC 
(rev 10948)
@@ -23,9 +23,10 @@
        private HashMap<Integer,MessageHandler> messageHandlers; // By ID
        private LruCache<Integer> chkStore;
        private LruCache<Integer> chkCache;
-       private LruMap<Integer,Integer> sskStore; // SSKs can collide
+       private LruMap<Integer,Integer> sskStore; // SSKs can collide, use a Map
        private LruMap<Integer,Integer> sskCache;
-       private LruCache<Integer> pubKeyCache; // SSK public keys
+       private LruCache<Integer> pubKeyStore; // SSK public keys
+       private LruCache<Integer> pubKeyCache;
        private boolean decrementMaxHtl = false;
        private boolean decrementMinHtl = false;
        public TokenBucket bandwidth; // Bandwidth limiter
@@ -49,6 +50,7 @@
                chkCache = new LruCache<Integer> (16000);
                sskStore = new LruMap<Integer,Integer> (16000);
                sskCache = new LruMap<Integer,Integer> (16000);
+               pubKeyStore = new LruCache<Integer> (16000);
                pubKeyCache = new LruCache<Integer> (16000);
                if (Math.random() < 0.5) decrementMaxHtl = true;
                if (Math.random() < 0.25) decrementMinHtl = true;
@@ -161,6 +163,16 @@
                pubKeyCache.put (key);
        }

+       // Consider adding a public key to the store
+       public void storePubKey (int key)
+       {
+               if (closerThanPeers (keyToLocation (key))) {
+                       log ("public key " + key + " added to store");
+                       pubKeyStore.put (key);
+               }
+               else log ("public key " + key + " not added to store");
+       }
+       
        // Called by Peer to start the retransmission timer
        public void startTimer()
        {
@@ -314,7 +326,7 @@
                }
                if (!getToken (prev)) return;
                // Look up the public key
-               boolean pub = pubKeyCache.get (r.key);
+               boolean pub = pubKeyStore.get (r.key) || pubKeyCache.get(r.key);
                if (pub) log ("public key " + r.key + " found in cache");
                else log ("public key " + r.key + " not found in cache");
                // Accept the search
@@ -370,7 +382,7 @@
                }
                if (!getToken (prev)) return;
                // Look up the public key
-               boolean pub = pubKeyCache.get (i.key);
+               boolean pub = pubKeyStore.get (i.key) || pubKeyCache.get(i.key);
                if (pub) log ("public key " + i.key + " found in cache");
                else log ("public key " + i.key + " not found in cache");
                // Accept the search

Modified: 
trunk/apps/load-balancing-sims/phase7/sim/generators/SimplePublisher.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/generators/SimplePublisher.java   
2006-11-16 16:45:01 UTC (rev 10947)
+++ trunk/apps/load-balancing-sims/phase7/sim/generators/SimplePublisher.java   
2006-11-16 16:45:33 UTC (rev 10948)
@@ -1,5 +1,5 @@
-// A simple publisher that inserts CHKs using a Poisson process and informs
-// each reader of each key after an average of ten minutes
+// A simple publisher that inserts keys using a Poisson process and informs
+// each reader after an average of ten minutes

 package sim.generators;
 import sim.Event;
@@ -9,6 +9,9 @@

 public class SimplePublisher implements EventTarget
 {
+       // FIXME: what fraction of keys are CHKs in real life?
+       private final static double FRACTION_CHKS = 0.5;
+       
        public final double rate; // Inserts per second
        private int inserts; // Publish this many inserts (0 for unlimited)
        private Node node; // The publisher's node
@@ -30,10 +33,15 @@
                return readers.add (n);
        }

-       // Event callbacks
-       
        private void publish()
        {
+               // Randomly choose between publishing a CHK and an SSK
+               if (Math.random() < FRACTION_CHKS) publishChk();
+               else publishSsk();
+       }
+       
+       private void publishChk()
+       {
                // Insert a random key
                int key = Node.locationToKey (Math.random());
                node.generateChkInsert (key);
@@ -48,6 +56,22 @@
                Event.schedule (this, delay, PUBLISH, null);
        }

+       private void publishSsk()
+       {
+               // Insert a random key
+               int key = Node.locationToKey (Math.random());
+               node.generateSskInsert (key, 0);
+               // Inform each reader after an average of ten minutes
+               for (Node n : readers) {
+                       double delay = 595.0 + Math.random() * 10.0;
+                       Event.schedule (n, delay, Node.REQUEST_SSK, key);
+               }
+               // Schedule the next insert after an exp. distributed delay
+               if (inserts > 0 && --inserts == 0) return;
+               double delay = -Math.log (Math.random()) / rate;
+               Event.schedule (this, delay, PUBLISH, null);
+       }
+       
        // EventTarget interface

        public void handleEvent (int type, Object data)

Modified: 
trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java    
2006-11-16 16:45:01 UTC (rev 10947)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java    
2006-11-16 16:45:33 UTC (rev 10948)
@@ -158,6 +158,7 @@
        {
                searchState = COMPLETED;
                node.cachePubKey (key);
+               node.storePubKey (key);
                node.cacheSsk (key, data);
                node.storeSsk (key, data);
                node.removeMessageHandler (id);


Reply via email to