首页 \ 问答 \ 与Redis和Unicorn连接池的好处(Benefits of connection pooling with Redis and Unicorn)

与Redis和Unicorn连接池的好处(Benefits of connection pooling with Redis and Unicorn)

背景:我有一个Ruby / Rails + Nginx / Unicorn Web应用程序,连接到多个Redis DB(即我没有使用Redis.current ,而是使用全局变量进行不同的连接)。 我知道我需要在创建新的Unicorn worker时在after_fork块中创建一个新连接,如此此处所述

我的问题是关于连接池的需求。 根据这个 SO线程, “在Unicorn中,每个进程都建立自己的连接池,所以如果你的数据库池设置是5,你有5个Unicorn工作人员,那么你最多可以有25个连接。但是,因为每个独角兽工作者只能处理一次只有一个连接,那么除非你的应用程序在内部使用线程,否则每个worker只会实际使用一个db连接...池大小大于1意味着每个Unicorn worker都可以访问它不能使用的连接,但它赢了实际上打开连接,这没关系。“

由于我不使用Sidekiq,我甚至需要为Redis连接使用连接池吗? 池大小为1的连接池有什么好处吗? 或者我应该简单地使用单个连接的变量 - 例如Redis.new(url:ENV [“MY_CACHE”])?


Background: I have a Ruby/Rails + Nginx/Unicorn web app with connections to multiple Redis DBs (i.e. I am not using Redis.current and am instead using global variables for my different connections). I understanding that I need to create a new connection in the after_fork block when a new Unicorn worker is created, as explained here and here.

My question is about the need for connection pooling. According to this SO thread, "In Unicorn each process establishes its own connection pool, so you if your db pool setting is 5 and you have 5 Unicorn workers then you can have up to 25 connections. However, since each unicorn worker can handle only one connection at a time, then unless your app uses threading internally each worker will only actually use one db connection... Having a pool size greater than 1 means each Unicorn worker has access to connections it can't use, but it won't actually open the connections, so that doesn't matter."

Since I am NOT using Sidekiq, do I even need to use connection pools for my Redis connections? Is there any benefit of a connection pool with a pool size of 1? Or should I simply use variables with single connections -- e.g. Redis.new(url: ENV["MY_CACHE"])?


原文:https://stackoverflow.com/questions/37691120
更新时间:2022-06-17 09:06

最满意答案

对于Swift <= 4.0,您可以使用os()配置测试功能:

#if os(iOS)
  import CoreTelephony
#endif

您还必须包装使用CoreTelephony代码。

os()所有可用测试包括: OSXiOSwatchOStvOSLinuxWindowsFreeBSD

对于Swift> = 4.1,您还可以使用canImport()

#if canImport(CoreTelephony)
  import CoreTelephony
#endif

For Swift <= 4.0 you can use the os() configuration test function:

#if os(iOS)
  import CoreTelephony
#endif

You'll have to wrap code that uses CoreTelephony as well.

All available tests for os() are: macOS, iOS, watchOS, tvOS, Linux, Windows, and FreeBSD.

For Swift >= 4.1 you can also use canImport():

#if canImport(CoreTelephony)
  import CoreTelephony
#endif

相关问答

更多
  • 桥 1.创建一个xxx-Bridging-Header 使用您选择的方法将桥接头添加到项目中,最简单的方法是创建一个.m文件,然后在此对话框中回答Create Bridging Header : 2.在桥接头中引用您的Pod 包含您的文件,如下所示: // // Use this file to import your target's public headers that // you would like to expose to Swift. #import "RTCICEServer.h" ...
  • 您需要创建一个从C ++到Objective C或普通C的桥梁。然后,您需要将桥接头包含/导入到“Objective-C桥接头”中,当您添加Swift源时应该生成Xcode应该生成的头文件文件在现有项目中。 You will need to create a bridge from C++ to Objective C or plain C. After that, you will need to include/import the bridge's header into an "Objective- ...
  • 如果我正确地得到你,你没有一个单独的构建目标为您的框架(您已经使用XCode 5构建它),并将框架包含在您的项目的构建目标。 您所指的文档的一部分是关于不同目标内的框架。 由于您的框架在项目的目标中,这部分文档不适用于此。 在您的情况下,您无法在Swift文件中导入框架。 这就是为什么你收到错误信息“没有这样的模块myFramework” 。 myFramework不是模块 - 它是您项目模块的一部分(默认情况下由您的产品名称决定)。 因此,您的框架中的类可以访问。 但是,您的框架是用Objective-C ...
  • 对于Swift <= 4.0,您可以使用os()配置测试功能: #if os(iOS) import CoreTelephony #endif 您还必须包装使用CoreTelephony代码。 os()所有可用测试包括: OSX , iOS , watchOS , tvOS , Linux , Windows和FreeBSD 。 对于Swift> = 4.1,您还可以使用canImport() : #if canImport(CoreTelephony) import CoreTelephony ...
  • 您实际可以构建一个“正常工作”的解决方案(无需将module.modulemap和SWIFT_INCLUDE_PATHS设置复制到您的项目,根据其他解决方案的要求),但它确实需要您创建一个虚拟框架/模块,您可以将适当导入您的框架。 我们也可以确保它的工作,无论平台( iphoneos , iphonesimulator或macosx )。 在项目中添加一个新的框架目标,并将其命名为系统库, 例如 “CommonCrypto”。 (您可以删除伞头, CommonCrypto.h 。) 添加一个新的配置设置文件 ...
  • 所以我找到了一个解决方法。 我正在Objective-C文件中实现与框架的集成,并将此方法公开给我的swift。 So I found a workaround. I am implementing the integration with the framework in a Objective-C file and exposing this methods to my swift.
  • 您需要将libstdc++.dylib添加到项目的“常规”选项卡中的“链接的框架和库”中。 You need to add libstdc++.dylib to the Linked Frameworks and Libraries in the General tab for your project.
  • 对于Swift 3: extension ZBarSymbolSet: Sequence { public func makeIterator() -> NSFastEnumerationIterator { return NSFastEnumerationIterator(self) } } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo ...
  • 仅供参考,您现在可以使用master分支为FMDB构建框架,并且不再需要使用我在下面讨论过的swiftFramework分支。 (该分支的创建是因为Xcode 6和7中存在一个问题,导致无法创建引用非模块化头文件的框架。) 例如,请参阅问题# 540 ,了解如何使用Carthage构建框架的示例。 注意,您不必使用Carthage,但它表明不再需要swiftFramework分支。 为了历史目的,我会在下面保留原始答案,但它似乎不再适用。 我们现在可以在Xcode 8中构建FMDB框架而不会发生任何事故。 ...
  • 决不。 你永远不需要导入类 。 您需要导入模块 。 任何时候,如果您想在一个模块中使用来自另一个模块的任何内容,则必须导入该模块。 如果你想导入你自己的定制模块,你首先需要一个框架。 为您的项目添加一个框架。 我命名了我的MyFramework (并创建了一个测试目标): 现在,请确保您的框架与您的主要目标(或您想要使用的任何目标)相关联: 如果不在这里,请使用加号按钮添加它。 现在,去导入它: 并且请注意,从这个目标中,如果标记为public则只能使用MyFramework内容。 Never. You n ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。