Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 书架-设置哈希时性能不佳_C#_Redis_Booksleeve - Fatal编程技术网

C# 书架-设置哈希时性能不佳

C# 书架-设置哈希时性能不佳,c#,redis,booksleeve,C#,Redis,Booksleeve,我正在更新我的web服务以使用最新的库1.3.38。以前我使用的是1.1.0.7 在做一些基准测试时,我注意到使用新版BookSleeve在Redis中设置哈希比旧版慢很多倍。请考虑以下C标杆标号: public void TestRedisHashes() { int numItems = 1000; // number of hash items to set in redis int numFields = 30; // number of fields in each redi

我正在更新我的web服务以使用最新的库1.3.38。以前我使用的是1.1.0.7

在做一些基准测试时,我注意到使用新版BookSleeve在Redis中设置哈希比旧版慢很多倍。请考虑以下C标杆标号:

public void TestRedisHashes()
{
  int numItems = 1000; // number of hash items to set in redis 
  int numFields = 30; // number of fields in each redis hash
  RedisConnection redis = new RedisConnection("10.0.0.01", 6379);
  redis.Open();

  // wait until the connection is open
  while (!redis.State.Equals(BookSleeve.RedisConnectionBase.ConnectionState.Open)) { }

  Stopwatch timer = new Stopwatch();
  timer.Start();
  for (int i = 0; i < numItems; i++)
  {
    string key = "test_" + i.ToString();

    for (int j = 0; j < numFields; j++)
    {
      // set a value for each field in the hash
      redis.Hashes.Set(0, key, "field_" + j.ToString(), "testdata");
    }
    redis.Keys.Expire(0, key, 30); // 30 second ttl
  }
  timer.Stop();

  Console.WriteLine("Elapsed time for hash writes: {0} ms", timer.ElapsedMilliseconds);
}
public void TestRedisHashes()
{
int numItems=1000;//要在redis中设置的哈希项数
int numFields=30;//每个redis哈希中的字段数
再连接再连接=新的再连接(“10.0.0.01”,6379);
redis.Open();
//等待连接打开
而(!redis.State.Equals(booksheeve.RedisConnectionBase.ConnectionState.Open)){}
秒表计时器=新秒表();
timer.Start();
对于(int i=0;i
BookSleeve 1.1.0.7在Redis 2.6中设置1000个哈希值大约需要20毫秒,而1.3.38大约需要400毫秒。慢了20倍!我测试过的BookSleeve 1.3.38的其他部分要么和旧版本一样快,要么比旧版本更快。我还尝试了使用Redis2.4进行相同的测试,并将所有内容包装到事务中。在这两种情况下,我得到了相似的表现


还有人注意到这样的事情吗?我一定是做错了什么。。。我是否使用新版BookSleeve正确设置哈希值?这是执行开火和遗忘命令的正确方法吗?我已经把它作为如何使用哈希的一个例子,但是没有找到我所做的不同之处。在这种情况下,最新版本是否可能只是较慢?

要实际测试总体速度,您需要添加等待最后一条消息处理的代码,例如:

  Task last = null;
  for (int i = 0; i < numItems; i++)
  {
    string key = "test_" + i.ToString();

    for (int j = 0; j < numFields; j++)
    {
      // set a value for each field in the hash
      redis.Hashes.Set(0, key, "field_" + j.ToString(), "testdata");
    }
    last = redis.Keys.Expire(0, key, 30); // 30 second ttl
  }
  redis.Wait(last);
SuspendFlush()
/
resumesflush()
对是在单个线程上调用大量操作以避免任何额外刷新的理想选择。要复制intellisense注释,请执行以下操作:

//
// Summary:
// Temporarily suspends eager-flushing (flushing if the write-queue becomes
// empty briefly). Buffer-based flushing will still occur when the data is full.
// This is useful if you are performing a large number of operations in close
// duration, and want to avoid packet fragmentation. Note that you MUST call
// ResumeFlush at the end of the operation - preferably using Try/Finally so
// that flushing is resumed even upon error. This method is thread-safe; any
// number of callers can suspend/resume flushing concurrently - eager flushing
// will resume fully when all callers have called ResumeFlush.
//
// Remarks:
// Note that some operations (transaction conditions, etc) require flushing
// - this will still occur even if the buffer is only part full.

请注意,在大多数高吞吐量场景中,有多个操作来自多个线程:在这些场景中,来自并发线程的任何工作都将自动排队,从而最大限度地减少线程数。

感谢您的详细回答!只要I.Wait()等待操作完成,使用Suspend/resumesflush似乎可以使性能与1.1.0.7保持一致。在1.2.0.8和1.3之间的发行说明中提到的主要变化之一是删除专用的writer线程吗?@burnsuv是的,基本上;引用发行说明:“1.3.*-主要更改;1.3删除了线程内核,以便在多个连接上实现更大的可扩展性
//
// Summary:
// Temporarily suspends eager-flushing (flushing if the write-queue becomes
// empty briefly). Buffer-based flushing will still occur when the data is full.
// This is useful if you are performing a large number of operations in close
// duration, and want to avoid packet fragmentation. Note that you MUST call
// ResumeFlush at the end of the operation - preferably using Try/Finally so
// that flushing is resumed even upon error. This method is thread-safe; any
// number of callers can suspend/resume flushing concurrently - eager flushing
// will resume fully when all callers have called ResumeFlush.
//
// Remarks:
// Note that some operations (transaction conditions, etc) require flushing
// - this will still occur even if the buffer is only part full.