dartist / redis_client

A high-performance async/non-blocking Redis client for Dart
BSD 2-Clause "Simplified" License
100 stars 29 forks source link

the clinet in web application is slow , take 30-40millesecond #25

Closed wxf4150 closed 10 years ago

wxf4150 commented 11 years ago

i had use the branch lastdart; i use the incr(key) once;

DateTime dt = new DateTime.now(); RedisClient rclient; RedisClient.connect("192.168.3.19:6379").then((client){rclient=client;}).then((e){ dt = new DateTime.now(); rclient.incr("testkey").then((counter){ var span=new DateTime.now().difference(dt); print("redis write times:$counter/$i;spend:${span.inMilliseconds}");}); });

it slow:
in command-line appllication it take 15-30millesecond, web application it take 30-40 millesecond very slow

and i test the dart-memcahed client's incr function too. web application use dart-mecached take 1 or 2 millesecond. very quickly command-line appllication which use dart-mecached take 30-40 Millisecond

the web code is use: DateTime dt = new DateTime.now(); if (dbtype==1) // dart-mecached take 1 or 2 millesecond. very quickly mclient.increment('key:$counter_id', 1) .then((counter){ request.response.write("mclient key:$counter;spend${(new DateTime.now()).difference(dt).inMilliseconds}"); request.response.close();}, onError:(error){ if(error == OPStatus.KEY_NOT_FOUND ){ mclient.set("key:$counter_id",encodeUtf8("1")); request.response.write('key:1'); request.response.close();}} ); else //the redis-dart client take 30-40 millesecond very slow rclient.incr("key$counter_id").then( (counter){ request.response.write("redis key:$counter_id;value:$counter;spend${(new DateTime.now()).difference(dt).inMilliseconds}"); request.response.close();}, onError:(e){ } //,onError:(e){ request.response.close();} );

bbss commented 10 years ago

With your example modified like this:

test('latency', () {
  DateTime dt;
  RedisClient rclient;
  RedisClient.connect("127.0.0.1:6379").then((client){rclient=client;}).then((e){
    dt = new DateTime.now();
    rclient.incr("testkey").then((counter){
      var span=new DateTime.now().difference(dt);
      print("redis write times:$counter;spend:${span.inMilliseconds}");});
  });
});

When I run this code on my machine and a local Redis instance it gives me about a 2 millisec delay. Is your redis instance on a different machine? Because latency substantially increases once it has to deal with networks. Also there have been some changes in this build so this might be fixed for you too, let us know!