【发布时间】:2016-03-29 06:38:24
【问题描述】:
我们当前的缓存实现在报表对象中缓存大量数据(在某些情况下为 50MB)。
我们已经从内存缓存转移到文件缓存,并使用 ProtoBuf 进行序列化和反序列化。这很好用,但是我们现在正在尝试使用 Redis 缓存。 下面是一个例子,说明 Redis 比使用文件系统需要多长时间。 (注意:在设置字节数组时,使用 protobuf 代替 JsonConvert 可将设置时间提高到 15 秒,并将获取时间提高到 4 秒)。
// Extremely SLOW – caching using Redis (JsonConvert to serialize/de-serialize)
IDatabase cache = Connection.GetDatabase();
// 23 seconds!
cache.StringSet("myKey", JsonConvert.SerializeObject(bigObject));
// 5 seconds!
BigObject redisResult = JsonConvert.DeserializeObject<BigObject>(cache.StringGet("myKey"));
// FAST - caching using file system (protobuf to serialize/de-serialize)
IDataAccessCache fileCache = new DataAccessFileCache();
// .5 seconds
fileCache.SetCache("myKey",bigObject);
// .5 seconds
BigObject fileResult = fileCache.GetCache<BigObject>("myKey");
提前感谢您的帮助。
ps。我没有找到类似问题的答案。 Caching large objects - LocalCache performance
或
【问题讨论】:
-
你能把序列化和缓存插入分开,以确定什么是耗时的吗?这可能是JSON序列化。尝试不同的序列化方法,即BinaryFormatter。
-
感谢您的快速回复。序列化只有大约 1 秒(23 秒)。当我们从内存转移到文件存储时,我们从 BinaryFormatter 开始,但它“慢”,所以我们切换到 ProtoBuf。我会试一试。
-
对象序列化有多大?你试过压缩吗?即This