gpt4 book ai didi

azure - stackexchange redis,读取大文件=超时

转载 作者:可可西里 更新时间:2023-11-01 11:13:11 26 4
gpt4 key购买 nike

我有一个使用大内存文件(略低于 2GB)的应用程序。

我正在尝试使用 Redis 列表(在 Azure 中)作为存储(相对于 SQL)。在 Redis 中构建列表非常快,我可以在大约 5 分钟内加载 Redis 列表,但随后我需要从列表中读取数据到应用程序中。

这非常慢,我尝试过增加线程、延长同步超时等但无济于事。

ThreadPool.SetMinThreads(200, 200);   

我正在使用我在网上发现的 Redis 列表的 C# 实现,我将其传递给通过 foreach 循环构建内存集合的代码。在内部,这就是它处理数据的方式(我省略了类的其余部分)

    public class RedisList<T> : IList<T>
{
private static ConnectionMultiplexer _cnn;
private readonly string _key;

private static readonly Lazy<ConnectionMultiplexer> LazyConnection = new Lazy<ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(ConfigurationManager.AppSettings["AzureRedisCacheUrl"]));

public ConnectionMultiplexer Connection => LazyConnection.Value;
public RedisList(string key)
{
this._key = key;
_cnn = Connection;
}

public IEnumerator<T> GetEnumerator()
{
for (var i = 0; i < this.Count; i++)
{
yield return Deserialize<T>(GetRedisDb().ListGetByIndex(_key, i).ToString());
}
}
}

是否有更有效的读取数据的方法?我这样做是不是疯了? :D 谢谢

最佳答案

Am I insane to do it this way?

绝对是的。 Redis 并非设计用于存储大型二进制数据,如 < 2GB 文件(甚至 100MB 文件)。

Redis 旨在对小数据 block 建立索引,以便以后在 CPU 和内存方面以非常优化且高效的方式检索它们。请记住,Redis 是一个内存数据库,将其数据快照到磁盘(例如 RDB 文件)的事实并不意味着数据源是您的 RAM 内存。

无需将如此大的二进制数据存储在 Redis 上,只需使用 Redis 作为文件索引,并利用其数据结构轻松获取它们。

OP 在一些评论中说:

Hi Matias, the redis list is a collection of individual files ranging from a few kb to around 5mb. The legacy application I'm working on loads all this into a huge static object on application start (I know, awful). The original version was an in memory file loaded from SQL, this proved too slow when moving to azure so we need a faster intermediary store of the data

无论如何,Redis 并不是设计为内存文件存储的。

我想说你应该看看memory-mapped files ,您甚至可以将所有文件加载到内存映射文件中,并使用索引获取它们(例如,从字节 0 到 243843、is file1 等)。这应该会提高整体性能,并且您不需要使用错误的工具来完成这项工作。

关于azure - stackexchange redis,读取大文件=超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39599121/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com