Package org.jredis.ri.alphazero

Examples of org.jredis.ri.alphazero.JRedisPipeline


     * @param spec
     * @param reqCnt
     * @param forever
     */
    private static void runJRedisPipelineINCR (ConnectionSpec spec, int reqCnt, int size, boolean forever) {
      JRedisFuture pipeline = new JRedisPipeline(spec);
      long totTime = 0;
      long avgRespTime = 0;
      float avgThroughput = (float)0;
      long iters = 0;
      try {
        String key = "pipeCounter";
      Future<Boolean> futureBool = pipeline.del(key);
      futureBool.get();
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<Long> futureLong = null;
          while(cnt < reqCnt){
            futureLong = pipeline.incr(key);
            cnt++;
          }
          long reqDoneTime = timer.mark();
        long counter = futureLong.get();
          long respDoneTime = timer.mark();
        System.out.format("JRedisPipeline: %d INCRs invoked   @ %5d  (%.2f ops/s)\n", cnt, reqDoneTime, timer.opsPerSecAtDelta(cnt, reqDoneTime));
        System.out.format("JRedisPipeline: %d INCRs completed @ %5d  (%.2f ops/s) [%d msecs to comp] \n", cnt, timer.deltaAtMark(), timer.opsPerSecAtMark(cnt), respDoneTime-reqDoneTime);
        System.out.format ("counter is now: %d\n\n", counter);
        if(iters > 0){
          totTime += reqDoneTime;
          avgRespTime = (totTime) / (long)iters;
          avgThroughput =(float)( reqCnt * 1000) / (float) avgRespTime;
          System.out.format("JRedisPipeline: %d INCRs average response time @ %dms (%.2f ops/s) \n", cnt, avgRespTime, avgThroughput);
        }
        iters ++;
        System.out.println ();
        } while(forever);

        pipeline.quit();
        }
        catch (ProviderException e) {
          e.printStackTrace();
        }
        catch (InterruptedException e) {
View Full Code Here


  private static void exampleUseofSyncInPipeline (ConnectionSpec connectionSpec) {
     
      // Note that we are using a JRedisPipeline reference and not a generic
      // JRedisFuture here -- this exposes the additional
     
      JRedisPipeline pipeline = new JRedisPipeline(connectionSpec);
     
      /*
       * Alright, so a hokey example of situations where we would like to
       * asynchronously pipeline a bunch of commands, and then at various point in
       * the process need to sync up with redis and get values before continuing.
       *
       * Obviously we can do this using JRedisFuture as well by calling get() on the
       * returned Future object, but the sync() method may be enhanced in future to
       * provide additional features.  Regardless, it does some of the boiler plate
       * ExecutionException handling code so its a bit prettier.
       */
      try {
        long start = System.currentTimeMillis();
       
        /* a sequence of asynchronous calls */
       
          pipeline.ping();
          pipeline.flushdb();

          Random rand = new Random();
          byte[] data = new byte[8];
          for(int i=0; i<1000000; i++){
            rand.nextBytes(data);
            pipeline.lpush("my-list", data);
          }
          /*
           * switch to synchronous semantics
           * the following call will block until
           * all the responses for above + the llen()
           * itself have been received.
           */
         
          long llen = pipeline.sync().llen("my-list");
         
          String cntrKey = "my-cntr";
          for(int i=0; i<100000; i++) {
            pipeline.incr(cntrKey);
          }
          /* sync call */
          long cntr = toLong (pipeline.sync().get(cntrKey));
         
          for(int i=0; i<100000; i++){
            pipeline.set("random:"+i, "value:" + rand.nextInt());
          }
          /* sync call */
          String randomVal = toStr (pipeline.sync().get("random:"+999));
         
          pipeline.flushdb();
        System.out.format ("end using sync() = %d msec\n", System.currentTimeMillis() - start);
         
          System.out.format("%s => %d\n", cntrKey, cntr);
          System.out.format("%s => %s\n", "random:"+999, randomVal);
          System.out.format("%s has %s items\n", "my-list", llen);
         
        }
        catch (RedisException e) {
          Log.problem("RedisException: " + e);
        }
        finally{
          pipeline.sync().quit();
          Log.log("shutting down.");
        }
    }
View Full Code Here

  /* (non-Javadoc)
   * @see org.jredis.examples.UsingJRedisFuture#getProviderInstance(org.jredis.connector.ConnectionSpec)
   */
  @Override
  protected JRedisFuture getProviderInstance (ConnectionSpec connectionSpec) {
    return new JRedisPipeline(connectionSpec);
  }
View Full Code Here

    /**
     * @param spec
     */
    @SuppressWarnings("boxing")
  private static void usingSynchSemantics (ConnectionSpec spec) {
      JRedisPipeline pipeline = new JRedisPipeline(spec);
      try {
        long start = System.currentTimeMillis();
          pipeline.ping();
          pipeline.flushall();
          String cntrKey = "my-cntr";
         
          Random rand = new Random();
          byte[] data = new byte[8];
          for(int i=0; i<100000; i++)
            pipeline.incr(cntrKey);
         
          long cntr = toLong (pipeline.sync().get(cntrKey));
         
          for(int i=0; i<100000; i++){
            rand.nextBytes(data);
            pipeline.set("random:"+i, "value:" + rand.nextInt());
          }
          String randomVal = toStr (pipeline.sync().get("random:"+999));
        System.out.format ("end using sync() = %d msec\n", System.currentTimeMillis() - start);
         
          System.out.format("%s => %d\n", cntrKey, cntr);
          System.out.format("%s => %s\n", "random:"+999, randomVal);
         
        }
        catch (RedisException e) {
          Log.problem("RedisException: " + e);
        }
        finally{
          pipeline.sync().quit();
        }

    }
View Full Code Here

    private static void runJRedisPipelineGET (ConnectionSpec spec, int reqCnt, int size, boolean forever) {
      long totTime = 0;
      long avgRespTime = 0;
      float avgThroughput = 0;
      long iters = 0;
      JRedisFuture pipeline = new JRedisPipeline(spec);
      try {
        String key = "pipeKey";
        byte[] data = new byte[size];
        (new Random()).nextBytes(data);
      pipeline.del(key);
      pipeline.set(key, data);
     
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<byte[]> futureBytes = null;
          while(cnt < reqCnt){
            futureBytes = pipeline.get(key);
            cnt++;
          }
          long reqDoneTime = timer.mark();
          assert futureBytes != null;
        @SuppressWarnings("null")
        byte[] value = futureBytes.get();
          long respDoneTime = timer.mark();
//        System.out.format("JRedisPipeline: %d GETs invoked   @ %5d  (%.2f ops/s)\n", cnt, reqDoneTime, timer.opsPerSecAtDelta(cnt, reqDoneTime));
        float throughput = timer.opsPerSecAtMark(cnt);
//        System.out.format("JRedisPipeline: %d GETs completed @ %5d  (%.2f ops/s) [%d msecs to comp] \n", cnt, timer.deltaAtMark(), throughput, respDoneTime-reqDoneTime);
        if(iters > 0){
          totTime += respDoneTime;
          avgRespTime = (totTime) / iters;
          avgThroughput =(float)( reqCnt * 1000) / (float) avgRespTime;
          System.out.format("JRedisPipeline: %d GETs [%d bytes/GET] average response time @ %dms (%.2f ops/s) last: %dms\n", cnt, data.length, avgRespTime, avgThroughput, respDoneTime);
//          Assert.isEquivalent(data, value);
        }
        iters ++;
//        System.out.println ();
        } while(forever);

        pipeline.quit();
        }
        catch (ProviderException e) {
          e.printStackTrace();
        }
        catch (InterruptedException e) {
View Full Code Here

    private static void runJRedisPipelinePING (ConnectionSpec spec, int reqCnt, int size, boolean forever) {
      long totTime = 0;
      long avgRespTime = 0;
      float avgThroughput = 0;
      long iters = 0;
      JRedisFuture pipeline = new JRedisPipeline(spec);
      try {
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<ResponseStatus> futureStat = null;
          while(cnt < reqCnt){
            futureStat = pipeline.ping();
            cnt++;
          }
          long reqDoneTime = timer.mark();
          assert futureStat != null;
        @SuppressWarnings("null")
        ResponseStatus rstat = futureStat.get();
          long respDoneTime = timer.mark();
//        System.out.format("JRedisPipeline: %d PINGs invoked   @ %5d  (%.2f ops/s)\n", cnt, reqDoneTime, timer.opsPerSecAtDelta(cnt, reqDoneTime));
        float throughput = timer.opsPerSecAtMark(cnt);
//        System.out.format("JRedisPipeline: %d PINGs completed @ %5d  (%.2f ops/s) [%d msecs to comp] \n", cnt, timer.deltaAtMark(), throughput, respDoneTime-reqDoneTime);
        if(iters > 0){
          totTime += reqDoneTime;
          avgRespTime = (totTime) / iters;
          avgThroughput =(float)( reqCnt * 1000) / (float) avgRespTime;
          System.out.print("\r");
          System.out.format("JRedisPipeline: %d PINGs average response time @ %dms (%.2f ops/s)", cnt, avgRespTime, avgThroughput);
        }
        iters ++;
//        System.out.println ();
        } while(forever);

        pipeline.quit();
        }
        catch (ProviderException e) {
          e.printStackTrace();
        }
        catch (InterruptedException e) {
View Full Code Here

          e.printStackTrace();
        }
    }
    @SuppressWarnings("boxing")
  private static void runJRedisPipelineLPUSH (ConnectionSpec spec, int reqCnt, int size, boolean forever) {
      JRedisFuture pipeline = new JRedisPipeline(spec);
      long totTime = 0;
      long avgRespTime = 0;
      float avgThroughput = 0;
      long iters = 0;
      try {
        String key = "pipeKey";
        byte[] data = new byte[size];
        (new Random()).nextBytes(data);
      Future<Long> futureLong = pipeline.del(key);
      futureLong.get();
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<ResponseStatus> futureStat = null;
          while(cnt < reqCnt){
            futureLong = pipeline.lpush(key, data);
            cnt++;
          }
          long reqDoneTime = timer.mark();
          assert futureStat != null;
          @SuppressWarnings({ "null", "unused" })
        ResponseStatus rstat = futureStat.get();
          long respDoneTime = timer.mark();
        System.out.format("JRedisPipeline: %d LPUSHs invoked   @ %5d  (%.2f ops/s)\n", cnt, reqDoneTime, timer.opsPerSecAtDelta(cnt, reqDoneTime));
        System.out.format("JRedisPipeline: %d LPUSHs completed @ %5d  (%.2f ops/s) [%d msecs to comp] \n", cnt, timer.deltaAtMark(), timer.opsPerSecAtMark(cnt), respDoneTime-reqDoneTime);
        if(iters > 0){
          totTime += reqDoneTime;
          avgRespTime = (totTime) / iters;
          avgThroughput =(float)( reqCnt * 1000) / (float) avgRespTime;
          System.out.format("JRedisPipeline: %d LPUSHs average response time @ %dms (%.2f ops/s) \n", cnt, avgRespTime, avgThroughput);
        }
        iters ++;
        System.out.println ();
        } while(forever);

        pipeline.quit();
        }
        catch (ProviderException e) {
          e.printStackTrace();
        }
        catch (InterruptedException e) {
View Full Code Here

     * @param reqCnt
     * @param forever
     */
    @SuppressWarnings("boxing")
  private static void runJRedisPipelineSET (ConnectionSpec spec, int reqCnt, int size, boolean forever) {
      JRedisFuture pipeline = new JRedisPipeline(spec);
      long totTime = 0;
      long avgRespTime = 0;
      float avgThroughput = 0;
      long iters = 0;
      try {
        String key = "pipeKey";
        byte[] data = new byte[size];
        (new Random()).nextBytes(data);
      Future<Long> futureLong = pipeline.del(key);
      futureLong.get();
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<ResponseStatus> futureStat = null;
          while(cnt < reqCnt){
            futureStat = pipeline.set(key, data);
            cnt++;
          }
          assert futureStat != null;
          @SuppressWarnings({ "null", "unused" })
        ResponseStatus rstat = futureStat.get();
          long respDoneTime = timer.mark();
        if(iters > 0){
          totTime += respDoneTime;
          avgRespTime = (totTime) / iters;
          avgThroughput =(float)( reqCnt * 1000) / (float) avgRespTime;
          System.out.format("JRedisPipeline: %d SETs [%d bytes/GET] average response time @ %dms (%.2f ops/s) \n", cnt, data.length, avgRespTime, avgThroughput);
        }
        iters ++;
        } while(forever);

        pipeline.quit();
        }
        catch (ProviderException e) {
          e.printStackTrace();
        }
        catch (InterruptedException e) {
View Full Code Here

     * @param reqCnt
     * @param forever
     */
    @SuppressWarnings("boxing")
  private static void runJRedisPipelineINCR (ConnectionSpec spec, int reqCnt, int size, boolean forever) {
      JRedisFuture pipeline = new JRedisPipeline(spec);
      long totTime = 0;
      long avgRespTime = 0;
      float avgThroughput = 0;
      long iters = 0;
      try {
        String key = "pipeCounter";
      Future<Long> futureDelCnt = pipeline.del(key);
      futureDelCnt.get();
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<Long> futureLong = null;
          while(cnt < reqCnt){
            futureLong = pipeline.incr(key);
            cnt++;
          }
          long reqDoneTime = timer.mark();
          assert futureLong != null;
        @SuppressWarnings("null")
        long counter = futureLong.get();
          long respDoneTime = timer.mark();
        System.out.format("JRedisPipeline: %d INCRs invoked   @ %5d  (%.2f ops/s)\n", cnt, reqDoneTime, timer.opsPerSecAtDelta(cnt, reqDoneTime));
        System.out.format("JRedisPipeline: %d INCRs completed @ %5d  (%.2f ops/s) [%d msecs to comp] \n", cnt, timer.deltaAtMark(), timer.opsPerSecAtMark(cnt), respDoneTime-reqDoneTime);
        System.out.format ("counter is now: %d\n\n", counter);
        if(iters > 0){
          totTime += reqDoneTime;
          avgRespTime = (totTime) / iters;
          avgThroughput =(float)( reqCnt * 1000) / (float) avgRespTime;
          System.out.format("JRedisPipeline: %d INCRs average response time @ %dms (%.2f ops/s) \n", cnt, avgRespTime, avgThroughput);
        }
        iters ++;
        System.out.println ();
        } while(forever);

        pipeline.quit();
        }
        catch (ProviderException e) {
          e.printStackTrace();
        }
        catch (InterruptedException e) {
View Full Code Here

TOP

Related Classes of org.jredis.ri.alphazero.JRedisPipeline

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.