- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
有时在插入一小堆不同的文档(同步)时,我会收到以下异常(请参阅下面的完整堆栈跟踪):
MongoDB.Driver.MongoWaitQueueFullException: The wait queue for acquiring a connection to server xyz.mongolab.com:54128 is full.
我在所有存储库之间使用单例 MongoDatabase
实例(因此是单个连接)。本质上,我正在做这样的事情(每个集合中不超过 20 个文档):
Context.Collection<ClientDocument>("clients").InsertMany(clients);
Context.Collection<VendorDocument>("vendors").InsertMany(vendors);
Context.Collection<SaleDocument>("sales").InsertOne(sale);
下面是单例上下文:
public class MongoContext
{
public IMongoDatabase Database { get; }
public MongoContext(IOptions<MongoSettings> settings)
{
var url = MongoUrl.Create(settings.Value.EndpointUri);
var client = new MongoClient(new MongoClientSettings()
{
Server = url.Server
});
Database = client.GetDatabase(url.DatabaseName);
}
public IMongoCollection<TDocument> Collection<TDocument>(string collection)
where TDocument : IDocument
{
return Database.GetCollection<TDocument>(collection);
}
}
在 MongoDB 的 Jira (https://jira.mongodb.org/browse/CSHARP-1144) 上提交了类似的内容,但这些案例处理的是大量的批量插入(并且通常是异步的)。
我认为没有必要通过这么小的插入来增加 MaxConnectionPoolSize 或 WaitQueueSize。
这可能是什么原因?
我正在使用托管在 mLabs 中的 MongoDB 3.0.7。我们的应用程序托管在 Azure 中(作为 Web 应用程序),我使用的是 C# 2.2.3 SDK。
MongoDB.Driver.MongoWaitQueueFullException: The wait queue for acquiring a connection to server xyz.mongolab.com:54128 is full. at MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquireConnectionHelper.CheckingOutConnection() at MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquireConnection(CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.ClusterableServer.GetChannel(CancellationToken cancellationToken) at MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken cancellationToken) at MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken) at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation'1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl'1.ExecuteWriteOperation[TResult](IWriteOperation`1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl'1.BulkWrite(IEnumerable'1 requests, BulkWriteOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionBase'1.InsertOne(TDocument document, InsertOneOptions options, CancellationToken cancellationToken)
编辑:
如果我将 MaxConnectionPoolSize 设置为 500 并将 WaitQueueSize 设置为 2000,则会出现以下异常:
MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 191.235.xxx.xxx:54128
实例化MongoClient
:
var client = new MongoClient(new MongoClientSettings()
{
Server = url.Server,
Credentials = credentials,
MaxConnectionPoolSize = 500,
WaitQueueSize = 2000
});
我最初提出了这个问题 here .这导致我试图弄清楚为什么我有这么多的联系。这导致了this post (质疑 Insert/InsertBulk 是否可能是一个原因)。无论如何,我仍然需要修复原来的 MongoWaitQueueFullException 问题。
最佳答案
解决问题的长期方法可能是引入节流机制,以确保不超过最大连接数。幸运的是,使用 Semaphore 很容易实现。
public class ConnectionThrottlingPipeline : IConnectionThrottlingPipeline
{
private readonly Semaphore openConnectionSemaphore;
public ConnectionThrottlingPipeline( IMongoClient client )
{
//Only grabbing half the available connections to hedge against collisions.
//If you send every operation through here
//you should be able to use the entire connection pool.
openConnectionSemaphore = new Semaphore( client.Settings.MaxConnectionPoolSize / 2,
client.Settings.MaxConnectionPoolSize / 2 );
}
public async Task<T> AddRequest<T>( Task<T> task )
{
openConnectionSemaphore.WaitOne();
try
{
var result = await task;
return result;
}
finally
{
openConnectionSemaphore.Release();
}
}
}
如果您通过此限制管道将所有请求发送到数据库,则永远不应达到限制。
在您的情况下,通过管道发送操作可能看起来像这样(您必须做出的重大改变是使您的数据库调用异步):
await connectionThrottlingPipeline.AddRequest(
Context.Collection<ClientDocument>("clients").InsertManyAsync(clients))
关于mongodb - MongoWaitQueueFullException : The wait queue for acquiring a connection to server is full,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37322110/
我试图弄清楚以下模块正在做什么。 import Queue import multiprocessing import threading class BufferedReadQueue(Queue.
如果我使用 Queue.Queue,那么我的 read() 函数不起作用,为什么?但是,如果我使用 multiprocessing.Queue,它运行良好: from multiprocessing
我正在寻找比我在文档中找到的更多关于 Python 队列实现的见解。 根据我的理解,如果我在这方面有误,请原谅我的无知: queue.Queue():通过内存中的基本数组实现,因此不能在多个进程之间共
当我使用多处理模块(Windows 上的 Python 2.7)中的队列代替 Queue.Queue 时,我的程序没有完全关闭。 最终,我想使用 multiprocessing.Process 处理
阅读了大量的 JavaScript 事件循环教程,我看到了不同的术语来标识队列存储消息,当调用堆栈为空时,事件循环准备好获取消息: 队列 消息队列 事件队列 我找不到规范的术语来识别它。 甚至 MDN
我收到错误消息“类型队列不接受参数”。当我将更改队列行替换为 PriorityQueue 时,此错误消失并且编译正常。有什么区别以及如何将其更改为编译队列和常规队列? import java.util
如何将项目返回到 queue.Queue?如果任务失败,这在线程或多处理中很有用,这样任务就不会丢失。 docs for queue.Queue.get()说函数可以“从队列中删除并返回一个项目”,但
如何在多个 queue.Queue 上进行“选择”同时? Golang 有 desired feature及其 channel : select { case i1 = 声明。 线程:queue 模
http://docs.python.org/2/library/queue.html#Queue.Queue.put 这似乎是一个幼稚的问题,但我在文档和谷歌搜索中都没有找到答案,那么这些方法是线程
这可能是个愚蠢的问题,但我对与 .dequeue() 和 $.queue() 一起使用的 .queue() 感到困惑> 或 jquery.queue()。 它们是否相同,如果是,为什么 jquery
我正在尝试创建一个线程化的 tcp 流处理程序类线程和主线程对话,但是 Queue.Queue 也没有做我需要的,服务器从另一个程序接收数据,我只想传递它进入主线程进行处理这里是我到目前为止的代码:
The principal challenge of multi-threaded applications is coordinating threads that share data or ot
在Queue模块的queue类中,有几个方法,分别是qsize、empty 和 full,其文档声称它们“不可靠”。 他们到底有什么不可靠的地方? 我确实注意到 on the Python docs网
我需要一个队列,多个线程可以将内容放入其中,并且多个线程可以从中读取。 Python 至少有两个队列类,Queue.Queue 和 collections.deque,前者似乎在内部使用后者。两者都在
明天我将介绍我选择进程内消息队列实现的基本原理,但我无法阐明我的推理。我的合作设计者提议我们实现一个简单的异步队列,只使用基本的作业列表和互斥锁来控制访问,我建议在嵌入式模式下使用 ActiveMQ。
在 scala 中定义了一个特征: trait Queue[T] Queue 是一种类型吗?或其他东西,例如类型构造函数? 来自 http://artima.com/pins1ed/type-para
我看到 SML/NJ 包含一个队列结构。我不知道如何使用它。如何使用 SML/NJ 提供的附加库? 最佳答案 Queue structure SML '97 未指定,但它存在于 SML/NJ 的顶级环
我是 D3 和 JavaScript 的新手。 我试图理解其中的 queue.js。 我已经完成了 this关联。但是仍然无法清楚地了解 queue.await() 和 queue.awaitAll(
所以我试图在我的 main.cpp 文件中调用一个函数,但我得到“错误:没有匹配函数来调用‘Queue::Queue()。” 队列.h #ifndef QUEUE_H #define QUEUE_H
假设我有一个 10 行的二维 numpy 数组 例如 array([[ 23425. , 521331.40625], [ 23465. , 521246.03125],
我是一名优秀的程序员,十分优秀!