【发布时间】:2017-08-21 19:57:02
【问题描述】:
我正在使用 C# 客户端“StackExchange.Redis”对 Redis 进行基准测试。 该数据集是一个包含近 1600 万条记录的文本文件。每条记录有六个条目,其中三个是双精度的,另外三个是整数。 当我使用 LPush(API 中的 LPushRight)时,将所有数据添加到 Redis 大约需要 4 分钟。 之后,当我使用(API 中的 LRange)检索数据时,检索所有列表大约需要 1.5 分钟。 我正在使用以下代码:
连接:
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
插入:
IEnumerable<string> lines =
File.ReadLines(@"C:\Hep.xyz");
List<string> linesList = lines.ToList();
int count = lines.Count();
string[] toks;
RedisValue[] redisToks = { "", "", "", "", "", "" };
for (int i = 0; i < count; i++)
{
toks = linesList[i].Split(' ', '\t');
for (int j = 0; j < 6; j++)
{
redisToks[j] = toks[j];
}
db.ListRightPushAsync("PS:DATA:", redisToks);
if (i % 1000000 == 0)
{
Console.WriteLine("Lines Read: {0}", i);
}
}
Console.WriteLine("Press any key to continue ...");
Console.ReadLine();
检索:
long len = db.ListLength("PS:DATA:");
long start = 0;
long end = 99999;
while (end < len)
{
RedisValue[] val = db.ListRange("PS:DATA:", start, end);
int length = val.Length;
start += 100000;
end += 100000;
}
Console.WriteLine("Press any key to continue ...");
Console.ReadLine();
对于配置:
我已将 maxmemory 设置为 4GB 并将 maxmemory-policy 设置为 volatile-lru
我在我的系统上本地运行所有这些。我的系统规格是 8 GB 内存 Inter Core i7 - 5500U CPU @ 2.4GHz(4 个 CPU),~2.4 GHz
能否请您帮我确定我需要研究的因素,以提高性能。还有,redis适合这种数据集吗?
【问题讨论】:
标签: c# redis stackexchange.redis