Package org.jredis

Examples of org.jredis.JRedisFuture


  @Override
  public void run() {
    int database = 11;
    ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes());
    JRedisFuture jredis = new JRedisChunkedPipeline(connSpec);
   
    byte[] key = "cpct".getBytes();
    int iters = 100000;
   
    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 {
        jredis.flush();
        long counter = frCounter.get()// NOTE: excellent place to put implicit flush()
        long delta_ns = System.nanoTime() - start;
        long delta_ms = TimeUnit.MILLISECONDS.convert(delta_ns, TimeUnit.NANOSECONDS);
        float opsrate = iters/delta_ms;
        Log.log("counter: %d  msec:%d ops/msecs:%f  [q-delta:%d] [delta:%d]", counter, delta_ms, opsrate, queued, delta_ns);
View Full Code Here


  }

  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

  }

  private void run() {
    int database = 11;
    ConnectionSpec connSpec = DefaultConnectionSpec.newSpec("localhost", 6379, database, "jredis".getBytes());
    JRedisFuture jredis = new JRedisAsyncClient(connSpec);
   
    byte[] key = "bench-jredis-pipeline-key".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

    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

     * @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

  public static void usingAsyncClient () {
    ConnectionSpec spec = DefaultConnectionSpec.newSpec()
    .setCredentials("jredis".getBytes())
    .setDatabase(10);

    JRedisFuture jredis = new JRedisAsynchClient(spec);

    System.out.println ("\nusing the AsyncClient: \n\n");
    useMSet(jredis);
    useMSetNX (jredis);
   
        jredis.quit();

  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.jredis.ri.ProviderTestBase#newProviderInstance()
   */
  @Override
  protected JRedisFuture newProviderInstance () {
    JRedisFuture provider = null;
    try {
      ConnectionSpec connectionSpec = DefaultConnectionSpec.newSpec(this.host, this.port, this.db2, this.password.getBytes());
      provider = new JRedisChunkedPipeline(connectionSpec);
        }
        catch (ClientRuntimeException e) {
View Full Code Here

TOP

Related Classes of org.jredis.JRedisFuture

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.