【问题标题】:"Timeout while getting a connection from pool." Hangfire.Postgres“从池中获取连接时超时。” Hangfire.Postgres
【发布时间】:2015-03-27 23:08:29
【问题描述】:

我是 Hangfire 的新手,所以我可能在某个地方搞砸了。我的 Hangfire 配置如下:https://github.com/HangfireIO/Hangfire#installation

但不是:

 config.UseSqlServerStorage("<connection string or its name>");

我有:

 config.UsePostgreSqlStorage("Server=127.0.0.1;Port=5432;User Id=postgres;Password=pwd;Database=Hangfire");

所以我在我的数据库中创建了一个 Hangfire 数据库。

然后,我正在构建和运行我的项目。没关系。在我的 postgres 中创建 Hangfire DB 中的所有表。效果很好。

但是,当我尝试时:

   BackgroundJob.Enqueue(() => HubService.SendPushNotificationToUsers(threadParticipants,  messageApi.SenderId, messageApi.SenderName, messageApi.ThreadId, messageApi.Content));

我收到 InnerMessage 异常:

  "Timeout while getting a connection from pool." postgres

我错过了什么吗?

【问题讨论】:

标签: c# asp.net-mvc postgresql timeout hangfire


【解决方案1】:

您是否尝试减少 HangFire 工作人员的数量? 也许这些正在消耗您的连接池,因为 Hangfire 默认使用 20 个工作人员 * X 个连接(不记得有多少,但它们是几个),这可能正在消耗您的连接池......因此连接超时......

您可以设置要在hangfire 初始化中使用多少个worker。 在此示例中,您将只使用 1 个工人...

app.UseHangfire(config =>
{
    config.UseServer(1);
});

【讨论】:

    【解决方案2】:

    尝试通过 ConnectionString 或 String Builder 关闭连接池。

    这是我们的做法

            var sb = new NpgsqlConnectionStringBuilder(connectionString);
            sb.Pooling = false;
            app.UseHangfire(config =>
            {
                config.UseActivator(new WindsorJobActivator(container.Kernel));
                config.UsePostgreSqlStorage(sb.ToString(), new PostgreSqlStorageOptions() { UseNativeDatabaseTransactions = true });
                config.UseServer();
            });
    

    【讨论】:

      猜你喜欢
      • 2012-04-19
      • 1970-01-01
      • 2014-07-07
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 2010-12-11
      • 2014-03-17
      相关资源
      最近更新 更多