注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

kangzye的博客

加Q群25382780切磋java,加19360923群研究JavaScript

 
 
 

日志

 
 

Large number of queues (HowTo)  

2011-04-02 11:32:41|  分类: ActiveMQ |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

from:http://www.goldenbug.net/tag/activemq/

We have the requirement of creating a very large number of queues (tens of thousands) in a single broker.  My searches turned up several others trying to do something similar, but with no results. We were recently able to accomplish this, so I decided to write a little howto. All of this information can be found in the mailing list, wiki, or XML reference, but it wasn’t easy to pull it all together.  Hopefully this will help someone.  Also, please let me know if there are any inaccuracies, or if anything can be added.

== Thread Count ==
=== “QueueThread” ===
One of the issues that you’ll come across is receiving the out of memory error “unable to create new native thread” when you create thousands of queues.  A “QueueThread” thread is created for every new queue.  The optimizedDispatch property for the queue policyEntry seemed to address our needs, the description states “don’t use a separate thread for dispatching from a Queue”  (http://activemq.apache.org/per-destination-policies.html). However, turning this on just seemed to create “TempQueue” threads instead, still creating a thread for each queue.  Digging a little deeper, we find that using OptimizedDispatch creates the thread using a TaskRunner, which should pool the threads.   After further research, we found that the property org.apache.activemq.UseDedicatedTaskRunner should be set to false so that the task runner actually pools the threads (http://activemq.apache.org/javalangoutofmemory.html — this document also provides other useful info, like
how to lower the stack size for each thread).

Example Policy Entry in INSTALL_DIR/conf/activemq.conf:
<policyEntries>
<policyEntry queue=”>” memoryLimit=”15mb” optimizedDispatch=’true’/>
</policyEntries>

You can either change the ‘UseDedicatedTaskRunner’ property in your startup script, INSTALL_DIR/bin/activemq:
ACTIVEMQ_OPTS=”-Xmx512M -Dorg.apache.activemq.UseDedicatedTaskRunner=false”
Or you can set ACTIVEMQ_OPTS in /etc/activemq.conf .

Note: It would be very useful it the documentation listed above referenced each other, as they are most useful when used together.

=== “Checkpoint” thread ===
If you’re using persistent storage, a “Checkpoint” thread is also created for every queue that is created. These are used to write persistent messages to the store.  Fortunately this is already created with a task runner, so setting the UseDedicatedTaskRunner property to false will prevent these thread from overhwelming your system.

=== Connection related threads ===
If you’re also dealing with high thread count due to a very high number of connections, see http://fusesource.com/wiki/display/ProdInfo/Understanding+the+Threads+Allocated+in+ActiveMQ.  Also, consider reducing the stack size for each thread (the JVM option -Xss).

== “too many open files” ==
ActiveMQ uses the amqPersistenceAdapter by default for persistent messages.  Unfortunately, this persistence adapter (as well as the kahaPersistenceAdapter) opens a file descriptor for each queue.  When creating large numbers of queues, you’ll quickly run into the limit for your OS.   There are two possible solutions to this:  1.) raise the per-process open file limit for your OS 2.) Use a jdbc persistent adapter.
The first can simply be googled for your OS.  The second uses a connection pool to your DB of choice, and no longer requires an open file for each queue created.

An unrelated issue is running out of file descriptors because there are too many connections.  (In linux, and other OSes, a file descriptor is used for open sockets).  I don’t know of any other way to handle that, other than increasing the limit for your process.

== Conclusion ==
We were able to create more than 20k queues using ~30 threads in a test environment with a 512MB heap.  Environment: ActiveMQ 5.2.0, SUN Java 1.6.0, Ubuntu 9.04 .  Our testing hasn’t been exhaustive, but everything is running smoothly so far.

  评论这张
 
阅读(685)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017