我正在尝试使用Azure中的Redis在我的应用程序中缓存。我的每个钥匙可以是2-4MB以上的每一个。当我在本地机器上针对Redis运行我的应用程序时,一切都很好,但是当在Azure上运行时性能很糟糕,检索密钥通常需要8-10秒,实际上,从原始源重新获取这些数据要比从缓存中重新获取数据要快。
所以我想第一个问题是,我的钥匙是不是太大了?我是不是只是用Redis把树弄错了?
如果没有,你知道为什么这么慢吗?该应用程序是一个Azure网站,该网站和redis实例位于同一区域。我正在使用stackexchange客户端并作为一个单例在global.asax文件中创建多路复用器,为了避免重新创建它,下面的代码如下:
Global.asax:
redisConstring = ConfigurationManager.ConnectionStrings["RedisCache"].ConnectionString;
if (redisConstring != null)
{
if (RedisConnection == null || !RedisConnection.IsConnected)
{
RedisConnection = ConnectionMultiplexer.Connect(redisConstring);
}
RedisCacheDb = RedisConnection.GetDatabase();
Application["RedisCache"] = RedisCacheDb;
}Web控制器:
IDatabase redisCache = System.Web.HttpContext.Current.Application["RedisCache"] as IDatabase;
string cachedJson = redisCache.StringGet(id);
if (cachedJson == null)
{
cachedJson=OutfitFactory.GetMembersJson(id);
redisCache.StringSet(id, cachedJson, TimeSpan.FromMinutes(15));
}
return OutfitFactory.GetMembersFromJson(cachedJson);发布于 2015-01-03 02:06:31
从评论上看,问题是带宽.所以:使用更少的带宽。想法:
作为参考,在SE,我们使用gzip压缩的protobuf net包装。
https://stackoverflow.com/questions/27750339
复制相似问题