尝试在Redis中的2组中插入750个项目时出现StackExchange TimeoutException [英] StackExchange TimeoutException when trying to insert 750 items in 2 sets in redis

查看:198
本文介绍了尝试在Redis中的2组中插入750个项目时出现StackExchange TimeoutException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初,我尝试将一些项目集合插入2个redis集(也许这根本不是个好主意,但是...).我尝试一次添加的条目数量: 750 +

Initially I'm trying to insert some collection of items into 2 redis sets (maybe this is not good idea at all, but ...). amount of entries that I'm trying to add at once: 750+

现在,当我尝试使用StackExchange.redis 客户端执行此操作时,我会收到超时异常,这很有趣,我可以使用旧版"书夹来完成类似的操作我之前调查过的客户.

For now I do receive timeout exception when trying to perform this action using StackExchange.redis client, the interesting thing that I'm able to complete similar action using "legacy" booksleeve client I've investigated previously.

因此,我肯定在某些方面(甚至在我的ine bookSleeve实现中)有错,只是试图找出到底哪里错了. 以下是我与redis客户端一起使用的代码示例: BookSleeve:

So, I definitely wrong in something (even maybe in my intial bookSleeve implementation), just trying to figure out what exactly is wrong. Below is sample of the code that I use with redis clients: BookSleeve:

using (var tran = connection.CreateTransaction())
{
Task lastOpTask = null;
tran.SuspendFlush();
try
{
    // perform required configurations/ actions
    tran.Sets.Add(_redisConfiguration.DbNumber, CurrentIdsSetDbKey, stringIds);
    tran.Sets.Add(_redisConfiguration.DbNumber, CurrentDetailsSetDbKey, stringDetails);
    lastOpTask = tran.Execute();
    isOperationSuccessful = true;
}
catch (TaskCanceledException ex)
{
    ...
}
catch (TimeoutException ex1)
{
    ...
}
finally
{
    tran.ResumeFlush();
}

if (lastOpTask != null)
{
    connection.Wait(lastOpTask);
    ...
}
}

StackExchange.redis的相同代码实现:

var tran = db.CreateTransaction();

// todo: do we need to add here any condition or PipeLining? any watch/unwatch verifications?
tran.SetAddAsync(CurrentIdsSetDbKey, stringIds);
tran.SetAddAsync(CurrentDetailsSetDbKey, stringDetails);

try
{
    isOperationSuccessful = tran.Execute();
}
catch (TaskCanceledException ex)
{
    ...
}
catch (TimeoutException ex1)
{
    ...
}

启动单元测试后,我收到StackExchange客户端的下一个错误:

After I start unit tests I receive next error for StackExchange client:

Message: Timeout performing EXEC, inst: 3, queue: 3, qu=0, qs=3, qc=0, wr=0/0

Source: in StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 1693 in StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 92 in StackExchange.Redis.RedisTransaction.Execute(CommandFlags flags) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\RedisTransaction.cs:line 51 in DFS.Cache.CacheManager.RedisStackExchange.RedisContestCacheManager.RegisterAvailableContests(IList1 contests) in d:\Projects\DFS\Code\DFS\DFS.Cache.CacheManager.RedisStackExchange\RedisContestCacheManager.cs:line 131

Source: in StackExchange.Redis.ConnectionMultiplexer.ExecuteSyncImpl[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 1693 in StackExchange.Redis.RedisBase.ExecuteSync[T](Message message, ResultProcessor1 processor, ServerEndPoint server) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\RedisBase.cs:line 92 in StackExchange.Redis.RedisTransaction.Execute(CommandFlags flags) in c:\TeamCity\buildAgent\work\18a91a3757cef937\StackExchange.Redis\StackExchange\Redis\RedisTransaction.cs:line 51 in DFS.Cache.CacheManager.RedisStackExchange.RedisContestCacheManager.RegisterAvailableContests(IList1 contests) in d:\Projects\DFS\Code\DFS\DFS.Cache.CacheManager.RedisStackExchange\RedisContestCacheManager.cs:line 131

我只是想知道,我到底在做什么错.预先感谢您的任何建议!.

P.S.对于stackEchange.redis配置,我使用的是Marc从github提供的配置示例(可在此处找到:StackExchange/StackExchange.Redis/blob/master/Docs/Configuration.md)

P.S. For stackEchange.redis configuration I'm using config sample provided by Marc from github (available here: StackExchange/StackExchange.Redis/blob/master/Docs/Configuration.md)

P.S. 请查看当前的StackExchange客户端配置文件:

P.S. Please see current StackExchange client Config file:

var config = new ConfigurationOptions
{
    EndPoints =
        {
            {"MasterIP", 6379},
            {"SlaveIP", 6380}
        },
    CommandMap = CommandMap.Create(new HashSet<string>
        {
            // EXCLUDE a few commands (to work with data-flow-related mode only)
            "INFO",
            "CONFIG",
            "CLUSTER",
            "PING",
            "ECHO",
            "CLIENT"
        }, available: false),
    KeepAlive = 60, // 60 sec to ensure connection is alive
    ConnectTimeout = 5000, // 5 sec
    SyncTimeout = 5000, // 5 sec
    ServiceName = "mymaster", // sentinel service name
    DefaultVersion = new Version(2, 8, 8),
    Password = "password"
};

(用于集合中的)标准条目如下:

Standard entry (used in sets) looks like:

{
    "Id":"08e5ffdbced046cb8f55c50e4bab822d",
    "Entries":0,
    "State":"i",
    "Name":"very dummy entry name value: autoGet 299",
    "Summary": "entry summary details, some long string 299, some common info, some data: true, 8200"
    "IsMultiple":true,
    "IsPublic":true,
    "MaxEntries":8200,
    "IsEntryVisible":true,
    "StartDate":"9/10/2014 12:00:00 AM"
}

P.S. 在Marc做出回应后,我进行了几次测试,并在单元测试中遇到了其他一些错误, 例如

P.S. After Marc's response I ran couple of tests and got some other errors in Unit tests, for example

{"Timeout performing SISMEMBER set:raw:Ids, inst: 1, queue: 6, qu=0, qs=6, qc=0, wr=0/0"} when set contains not more than 300 items. 

所以我同意这是Connection问题,与当前切换到StackExchange.redis客户端无关.

推荐答案

以下内容通过得很好,并在本地报告10ms.如果您能填补空白,我将非常感兴趣,这样我就可以做一个代表性的测试来重现该问题.请注意,qu=0, qs=3告诉我,在超时时,我们正在等待redis服务器响应.显然,本地带宽和延迟会很有趣,但是从根本上说,它应该可以工作.我也会对您的同步超时设置感兴趣.

The following passes just fine, and reports 10ms locally. I would be very interested if you could fill in the blanks a bit so I can do a representative test that reproduces the issue. Note that qu=0, qs=3 tells me that at the point that it times out, we're waiting for the redis server to respond. Obviously local bandwidth and latency would be of interest, but fundamentally, it should work. I'd also be interested in what your sync-timeout is set to.

using System.Diagnostics;
using System.Linq;
using NUnit.Framework;

namespace StackExchange.Redis.Tests.Issues
{
    [TestFixture]
    public class SO22786599 : TestBase
    {
        [Test]
        public void Execute()
        {
            string CurrentIdsSetDbKey = Me() + ".x";
            string CurrentDetailsSetDbKey = Me() + ".y";

            RedisValue[] stringIds = Enumerable.Range(1, 750).Select(i => (RedisValue)(i + " id")).ToArray();
            RedisValue[] stringDetails = Enumerable.Range(1, 750).Select(i => (RedisValue)(i + " detail")).ToArray();

            using (var conn = Create())
            {
                var db = conn.GetDatabase();
                var tran = db.CreateTransaction();

                tran.SetAddAsync(CurrentIdsSetDbKey, stringIds);
                tran.SetAddAsync(CurrentDetailsSetDbKey, stringDetails);

                var watch = Stopwatch.StartNew();
                var isOperationSuccessful = tran.Execute();
                watch.Stop();
                System.Console.WriteLine("{0}ms", watch.ElapsedMilliseconds);
                Assert.IsTrue(isOperationSuccessful);                
            }
        }
    }
}

这篇关于尝试在Redis中的2组中插入750个项目时出现StackExchange TimeoutException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆