Package org.jredis.ri.alphazero

Examples of org.jredis.ri.alphazero.JRedisPipeline


  }

  private void run() {
    int database = 11;
    ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes());
    JRedisFuture jredis = new JRedisPipeline(connSpec);
   
    byte[] key = "pipe".getBytes();
    int iters = 100 * 1000;
   
    try {
      cleandb(jredis);
    } catch (Throwable e) {
      e.printStackTrace();
      return;
    }
   
    for(;;){
      Future<Long> frCounter = null;
      long start = System.nanoTime();
      for(int i=0;i<iters; i++){
        frCounter = jredis.incr(key);
      }
      long queued = System.nanoTime() - start;
      try {
        long counter = frCounter.get();
        long delta_ns = System.nanoTime() - start;
View Full Code Here


  }
  final ConnectionSpec spec;
  JRedisFuture jredis = null;
  public AdHocTestNoConnection() throws Throwable{
    spec = DefaultConnectionSpec.newSpec("localhost", NOT_A_USUAL_REDIS_PORT, 11, "jredis".getBytes());
    jredis = new JRedisPipeline(spec);
  }
View Full Code Here

  public AdHocTestInfo(final Connection.Modality connmode) throws Throwable{
    this.connmode = Assert.notNull(connmode, "connmode", IllegalArgumentException.class);
    this.spec = DefaultConnectionSpec.newSpec().setCredentials("jredis".getBytes());
    switch (connmode) {
    case Asynchronous:
      jredis_async = new JRedisPipeline(spec);
      jredis = null;
      break;
    case Synchronous:
      jredis_async = null;
      jredis = new JRedisClient(spec);
View Full Code Here

    private static void exampleUseofSyncInPipeline (ConnectionSpec connectionSpec) {
     
      // Note that we are using a JRedisPipeline reference and not a generic
      // JRedisFuture here
     
      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();
       
          pipeline.ping();
          pipeline.flushdb();

          Random rand = new Random();
          byte[] data = new byte[8];
          for(int i=0; i<100000; i++){
            rand.nextBytes(data);
            pipeline.lpush("my-list", data);
          }
          /* sync call */
          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();
        }
    }
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
     */
    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 = (float)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();
        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) / (long)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 = (float)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();
        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) / (long)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

        catch (ExecutionException e) {
          e.printStackTrace();
        }
    }
    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 = (float)0;
      long iters = 0;
      try {
        String key = "pipeKey";
        byte[] data = new byte[size];
        (new Random()).nextBytes(data);
      Future<Boolean> futureBool = pipeline.del(key);
      futureBool.get();
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<ResponseStatus> futureStat = null;
          while(cnt < reqCnt){
            futureStat = pipeline.lpush(key, data);
            cnt++;
          }
          long reqDoneTime = timer.mark();
        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) / (long)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 spec
     * @param reqCnt
     * @param forever
     */
    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 = (float)0;
      long iters = 0;
      try {
        String key = "pipeKey";
        byte[] data = new byte[size];
        (new Random()).nextBytes(data);
      Future<Boolean> futureBool = pipeline.del(key);
      futureBool.get();
        do {
          int cnt = 0;
          Util.Timer timer = Timer.startNewTimer();
          Future<ResponseStatus> futureStat = null;
          while(cnt < reqCnt){
            futureStat = pipeline.set(key, data);
            cnt++;
          }
          long reqDoneTime = timer.mark();
        futureStat.get();
          long respDoneTime = timer.mark();
//        System.out.format("JRedisPipeline: %d SETs invoked   @ %5d  (%.2f ops/s)\n", cnt, reqDoneTime, timer.opsPerSecAtDelta(cnt, reqDoneTime));
//        System.out.format("JRedisPipeline: %d SETs completed @ %5d  (%.2f ops/s) [%d msecs to comp] \n", cnt, timer.deltaAtMark(), timer.opsPerSecAtMark(cnt), respDoneTime-reqDoneTime);
        if(iters > 0){
          totTime += respDoneTime;
          avgRespTime = (totTime) / (long)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 ++;
//        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.