- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我使用 BookSleeve 连接到我的 Redis 服务器并从中添加/获取条目时,我收到了一个 SocketException。具体的异常(exception)是:通常只允许每个套接字地址(协议(protocol)/网络地址/端口)的一种用法。
堆栈跟踪指向:BookSleeve.RedisConnectionBase.Wait(Task task) in d:\Dev\BookSleeve\BookSleeve\RedisConnectionBase.cs:2050
我的问题是我是否在我的代码中做错了(很可能)没有正确关闭连接或类似性质的东西?在大约 60 秒内执行大约 16000 次左右的操作后,往往会抛出异常。这似乎不是过多的操作,对吧?
相关代码如下,我很乐意提供任何其他信息。
public Cache.CacheEntry Get(string key, bool updateAccessed)
{
var cacheKey = GetCacheableKey(key);
using (var conn = GetUnsecuredConnection())
{
var entry = conn.Get<Cache.CacheEntry>(cacheKey);
return entry;
}
}
public override void Add(string key, Cache.CacheEntry entry)
{
var cacheKey = GetCacheableKey(key);
using (var conn = GetUnsecuredConnection())
{
using (var trans = conn.CreateTransaction())
{
trans.Set(cacheKey, entry);
trans.Strings.Increment(DbNum, CacheEntryCountKey);
trans.Strings.Increment(DbNum, CacheSizeKey, entry.DataLength);
trans.Sets.Add(DbNum, CacheKeysKey, cacheKey);
trans.Execute();
}
}
}
检索连接(这主要是从 BookSleeve 单元测试中复制的:
protected RedisConnection GetUnsecuredConnection(bool open = true, bool allowAdmin = false, bool waitForOpen = false)
{
var host = ConfigurationManager.AppSettings["Redis.BookSleeve.Host"];
var unsecuredPort = int.Parse(ConfigurationManager.AppSettings["Redis.BookSleeve.UnsecuredPort"]); //TODO: get this setting in a safer manner
var conn = new RedisConnection(host, unsecuredPort, syncTimeout: 5000, ioTimeout: 5000, allowAdmin: allowAdmin);
conn.Error += (s, args) => Log.Error(args.Exception.Message + args.Cause, args.Exception, typeof(RedisProviderBookSleeve));
if (open)
{
var openAsync = conn.Open();
if (waitForOpen) conn.Wait(openAsync);
}
return conn;
}
RedisConnection 对象的通用扩展方法:
public static T Get<T>(this RedisConnection conn, string key, int dbNum = 0)
{
if (typeof (T) == typeof (byte[]))
{
var task = conn.Strings.Get(dbNum, key);
var result = conn.Wait(task);
return (T) (object) result;
}
else
{
var task = conn.Strings.GetString(dbNum, key);
var result = conn.Wait(task);
if (result == null || typeof(T) == typeof(string))
return (T)(object)result;
return JsonSerializer.DeserializeFromString<T>(result);
}
}
public static void Set<T>(this RedisConnection conn, string key, T value, int dbNum = 0)
{
if (typeof (T) == typeof (byte[]))
{
conn.Strings.Set(dbNum, key, value as byte[]);
return;
}
var serializedValue = JsonSerializer.SerializeToString(value);
conn.Strings.Set(dbNum, key, serializedValue);
}
最佳答案
Marc 对这个问题的评论让我重新考虑我是如何利用连接的。我遇到了另一个问题的答案:
Maintaining an open Redis connection using BookSleeve
我最终使用了上述链接答案中的代码,删除了我发布的“GetUnsecuredConnection”方法,现在只需在构建/执行 Redis 操作之前检索打开的连接。
不再有 SocketException,一切似乎都按预期运行。感谢马克的提示!感谢@ofer-zelig 提供的连接代码。
public Cache.CacheEntry Get(string key, bool updateAccessed)
{
var cacheKey = GetCacheableKey(key);
var conn = RedisConnectionGateway.Current.GetConnection();
var entry = conn.Get<Cache.CacheEntry>(cacheKey);
return entry;
}
public override void Add(string key, Cache.CacheEntry entry)
{
var cacheKey = GetCacheableKey(key);
var conn = RedisConnectionGateway.Current.GetConnection();
using (var trans = conn.CreateTransaction())
{
trans.Set(cacheKey, entry);
trans.Strings.Increment(DbNum, CacheEntryCountKey);
trans.Strings.Increment(DbNum, CacheSizeKey, entry.DataLength);
trans.Sets.Add(DbNum, CacheKeysKey, cacheKey);
trans.Execute();
}
}
关于c# - Redis BookSleeve 套接字耗尽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20861281/
我们认为 Cloud Foundry 中的一组虚拟机存在 Azure SNAT 耗尽问题。这些机器不经过负载平衡器。 我已经浏览过这份文件: https://learn.microsoft.com/e
我正在使用 onSceneTouchEvent 在 TMX map 上移动玩家: @Override public Scene onCreateScene() { ...
关于这篇文章:Python del Statement , 我最近遇到了以下片段: # custom_process.py import threading import subprocess myL
我有一个具有多个线程的 python 应用程序,其中线程 2 到 n 可能会打开任意数量的文件。我想确保当线程 1 尝试打开文件时,它绝对不会因为文件描述符耗尽而失败。简而言之,我想保留文件描述符而不
我开发了一个 c# .net 4 应用程序,它每天对组织中的每台计算机(超过 70,000 台)执行 WMI 查询。由于与此线程无关的原因,我无法从服务器运行该应用程序,而是从我的 Windows X
我正在尝试在 pytorch 中实现 Yolo-v2。但是,我似乎只是通过网络传递数据而耗尽了内存。该模型很大,如下所示。但是,我觉得我在用我的网络做一些愚蠢的事情(比如不在某处释放内存)。网络在 c
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this qu
我在这里查看了几个与“太多客户”相关的主题,但仍然无法解决我的问题,所以我必须针对我的具体情况再次询问。 基本上,我设置了本地 Postgres 服务器并需要进行数万次查询,所以我使用了 Python
我正在使用 std::random_device 并想检查它的剩余熵。根据 cppreference.com: std::random_device::entropy double entropy()
我有以下 docker-compos.yml 文件: web: build: . ports: - "4200:4200" - "35729:35729" vo
如果 Linux 操作系统用完进程 ID 会怎样?是否会删除较旧的进程以释放空间以适应 future 的请求? 最佳答案 我假设您问的是达到进程限制时会发生什么。在这种情况下,系统不允许创建新进程,直
我们将 Azure SQL 用作单个数据库并在 DTU 定价模型下使用。我们有一个包含约 50M 条记录的表,我们想在单个字符串属性上添加一个新的非聚集索引。 问题是这是一个生产数据库。如果我使用简单
我们有多个服务总线监听器在应用服务内作为连续的 Azure Webjobs 运行。总共有 12 个监听器 Web 作业在同一个 S1 应用服务计划上运行。环境很小,每天总共大约有~1000-10000
Der Azure 网络专家, 我们的 Web 应用程序经常耗尽出站 TCP 连接。大多数出站连接实际上是 Azure 内部连接(SQL、BlobStore、后端服务)。但我们还没有虚拟网络和专用端点
我下载了一个简单的静态网络服务器的源代码 http://www.ibm.com/developerworks/systems/library/es-nweb/sidefile1.html 但是,我对第
我已经查看了有关 SO 的其他类似问题,但无法很好地将所有内容拼凑在一起。我有一个 Rails 应用程序(在 Heroku 上),它使用具有多进程和多线程的 Puma。我的应用程序还使用 Redis
在此代码中,如果我对 ParseForm() 调用进行注释,请求将按预期工作 package main import ( "fmt" "net/http" "net/url"
我不明白。 XSLX 表大约有 3MB 大,但即使是 1024MB 的 RAM 也不足以让 PHPExcel 将其加载到内存中吗? 我这里可能做错了什么: function ReadXlsxTable
我已配置 CachingConnectionFactory包装了一个 MQTopicConnectionFactory和 MQQueueConnectionFactory每个缓存大小设置为 10。 这
我正在检查 CodeEval 中的一些问题并在 PHP 中遇到这个奇怪的错误。我没有用其他语言遇到过这样的事情,所以我不知道为什么会发生这种情况。不包括整个答案(请不要帮我找到解决方案,除了 PHP
我是一名优秀的程序员,十分优秀!