宝途connect_xxx方法和连接池 [英] Boto connect_xxx method and connection pools

查看:227
本文介绍了宝途connect_xxx方法和连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我打电话boto.connect_xxx,其中xxx为某些服务(dynamodb,S3等)多次,它创建一个新的连接池每一次?我想要做的就是这样的事情(例如瓶):

If I call boto.connect_xxx, where xxx is some service (dynamodb, s3, etc) multiple times, does it create a new connection pool each time? What I'd like to do is something like this (example in Flask):

@app.before_request
def before_request():
    g.db = connect_dynamodb()

要确保我始终连接,但我不希望每个请求之前这样做,如果它会创建新的安全令牌等,整个rigamarole,每次。它是安全的只是调用connect_xxx()在应用程序启动时,一次,并依靠博托生成新的连接需要,等等。?

to make sure I always connect, but I don't want to do this before each request if it will create new security tokens, etc, the whole rigamarole, each time. Is it safe to just call connect_xxx() once when the application starts, and rely on boto to generate new connections as needed, etc.?

推荐答案

最好的方法是调用connect_xxx方法一次当你的应用程序启动并依靠博托管理从此连接。如果您使用的是多线程的唯一的例外规则。在这种情况下,每个线程应该创建它自己的连接自博托使用httplib的这是不线程

The best approach is to call the connect_xxx method once when your application starts and rely on boto to manage the connection from then on. The only exception to that rule is if you are using multiple threads. In that case, each thread should create it's own connection since boto uses httplib which is not threadsafe.

即使你每次打电话请求之前connect_xxx方法,你真的应该没问题。在类的级别和宝途池连接应在pretty的有效的方式处理这个问题。

Even if you call the connect_xxx method before each request, you really should be okay. Boto pools connection at the class level and should handle this in a pretty efficient manner.

这篇关于宝途connect_xxx方法和连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆