代码之家  ›  专栏  ›  技术社区  ›  bits8

Mongodb系统中打开的文件太多

  •  0
  • bits8  · 技术社区  · 6 年前

    我们的软件包括:

    centos、nginx、kestrel http服务器、dotnet core(v2.0.8)应用程序与mongodb(v3.6.7)合作

    kestrel http服务器有时会停止响应,似乎来自mongodb驱动程序连接的错误记录在第三行

    是什么导致了这个问题?

    我已经用这个主题将max open files选项配置为640000

    https://medium.com/@mshanak/soved-dotnet-core-too-many-open-files-in-system-when-using-postgress-with-entity-framework-c6e30eeff6d1

    但是没有解决的请帮我解决这个问题谢谢大家。

    May 17 12:37:36 myserver[14611]: fail: Microsoft.AspNetCore.Server.Kestrel[13]
    May 17 12:37:36 myserver[14611]: Connection id "0HLDRQRA00CP4", Request id "0HLDRQRA00CP4:00000001": An unhandled exception was thrown by the application.
    May 17 12:37:36 myserver[14611]: MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.Net.Sockets.SocketException: Too many open files in system
    May 17 12:37:36 myserver[14611]: at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateSocket(EndPoint endPoint)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of inner exception stack trace ---
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__48.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Servers.Server.<GetChannelAsync>d__30.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.Core.Operations.FindOperation`1.<ExecuteAsync>d__111.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__3`1.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperationAsync>d__83`1.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.MongoCollectionImpl`1.<UsingImplicitSessionAsync>d__91`1.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MongoDB.Driver.IAsyncCursorSourceExtensions.<FirstOrDefaultAsync>d__5`1.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MYData.UserCollection.<GetByIdAsync>d__2.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at MYAPI.Controllers.PostController.<GetForExplore>d__8.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
    May 17 12:37:36 myserver[14611]: --- End of stack trace from previous location where exception was thrown ---
    May 17 12:37:36 myserver[14611]: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    May 17 12:37:36 myserver[14611]: at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    May 17 12:37:36 myserver[14611]: at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.<ProcessRequestsAsync>d__2.MoveNext()
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   webmite    6 年前

    如果您使用的是CentOS 6或更高版本,则可能需要遵循 下面是说明。

    Red Hat Enterprise Linux和CentOS 6设置了最大进程限制 覆盖ulimit设置的1024个。创建一个名为 /etc/安全/限制。d/99 mongodb nproc。与新的软nproc和 增加过程限制的nproc硬值。看见 /etc/安全/限制。d/90 nproc。以conf文件为例

    您可以找到有关ulimit设置的更多详细信息 here