memcached客户端:打开,关闭和重用连接 [英] memcached client: opening, closing and reusing connections

查看:128
本文介绍了memcached客户端:打开,关闭和重用连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在测试spymemcached和xmemcached客户端.我一直在尝试在项目文档中找到答案,但这非常糟糕.

I have been testing spymemcached and xmemcached clients. I have been trying to find answers in the projects documentation but it is very poor.

我的问题是关于打开,关闭和重新使用连接的.我在一个文档中找到了它:

My questions are regarding opening, closing and reusing the connections. I found this in one document:

客户端可以在不再需要连接的任何时候关闭它.笔记, 但是,鼓励客户端缓存其连接,而不是 而不是每次需要存储或检索数据时都重新打开它们.缓存连接将消除与建立TCP连接相关的开销."

A client may just close the connection at any moment it no longer needs it. Note, however, that clients are encouraged to cache their connections rather than reopen them every time they need to store or retrieve data. Caching connections will eliminate the overhead associated with establishing a TCP connection".

Spymemcached不提供连接池,因此每次创建MemcachedClient实例时,我都在创建新的连接吗?那我什么时候应该关闭连接呢?我应该为我的应用程序中的所有线程提供相同的实例,还是每次都创建一个新实例?

Spymemcached doesn't provide a connection pool, so every time I create a MemcachedClient instance I am creating a new connection right? Then when should I close the connection? Should I provide the same instance to all the threads in my application or create a new one every time?

xmemcached确实有一个连接池.在这种情况下,我应该关闭从池中获得的连接吗?

xmemcached does have a connection pool. In this case should I close connections I get from the pool?

推荐答案

Spymemcached不提供连接池,因此每次创建MemcachedClient实例时,我都在创建新的连接吗?

Spymemcached doesn't provide a connection pool, so every time I create a MemcachedClient instance I am creating a new connection right?

是的,每次创建新的MemcachedClient对象时,都会创建一个新的连接.每个连接对于应用程序来说都是异步的,因此即使只有一个连接也可能足以满足您的应用程序的需求.但是,有些人确实建立了MemcachedClients连接池.

Yes, every time you create a new MemcachedClient object you create a new connection. Each connection appear asynchronous to the application so even having one connection will probably be enough for your application. Some people do however build a connection pool of MemcachedClients though.

那我什么时候应该关闭连接?

Then when should I close the connection?

您不再需要与memcached通信时就关闭连接.如果您的应用程序寿命很短,则由于MemcachedClient连接默认是守护程序连接,因此需要关闭连接以使jvm停止.

You shut down connections as soon as you no longer need to communicate with memcached. If you application is short lived you need to shutdown the connection in order to get the jvm to stop since MemcachedClient connections are daemon connections by default.

我应该为应用程序中的所有线程提供相同的实例,还是每次都创建一个新实例?

Should I provide the same instance to all the threads in my application or create a new one every time?

对多个线程使用相同的连接.由于创建TCP连接的开销,为每个调用创建新连接都会导致性能显着下降.

Use the same connection with multiple threads. Creating a new connection for each call will cause a significant performance drop because of the overhead of creating a TCP connection.

xmemcached确实有一个连接池.在这种情况下,我应该关闭从池中获得的连接吗?

xmemcached does have a connection pool. In this case should I close connections I get from the pool?

我对xmemcached并不熟悉,但是我想您可能只想创建几个(可能是16个)线程并与您的应用程序线程共享以达到最佳性能.

I'm not familiar with xmemcached, but I would imagine you would only want to create a few (16 maybe) threads and share them with your application threads for the best performance.

这篇关于memcached客户端:打开,关闭和重用连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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