Reducing the number of unwanted topics in the topic tree
The performance of a publish/subscribe system is improved by reducing the number of unwanted topics in the topic tree. What is an unwanted topic and how do you remove them?
You can create large numbers of topics without affecting performance adversely. However, some ways of using publish/subscribe result in continually expanding topic trees. An exceptionally large number of topics are created once and never used again. The growing number of topics might become a performance problem.
How can you avoid designs that lead to a large and growing number of unwanted topics? What can you do to help the queue manager remove unwanted topics from the topic tree?
The queue manager recognizes an unwanted topic because it has been unused for 30 minutes. The queue manager removes unused topics from the topic tree for you. The 30 minute duration can be changed by altering the queue manager attribute, TREELIFE. You can help the queue manager to remove unwanted topics by making sure that the topic appears to the queue manager to be unused. The section, What is an unused topic? explains what an unused topic is.
A programmer, designing any application, and especially designing a long running application, considers its resource usage: how much resource the program requires, are there any unbounded demands, and any resource leaks? Topics are a resource that publish/subscribe programs use. Scrutinize the use of topics just like any other resource a program uses.
What is an unused topic?
Before defining what an unused topic is, what exactly counts as a topic?
- USA
- USA/Alabama
- USA/Alabama/Auburn
To display all the topics in the topic tree, use the runmqsc command DISPLAY TPSTATUS('#') TYPE(TOPIC).
- It is not associated with a topic object
-
An administrative topic object has a topic string that associates it with a topic. When you define the topic object Alabama, if the topic, USA/Alabama, it is to be associated with does not exist, the topic is created from the topic string. If the topic does exist, the topic object and the topic are associated together using the topic string.
- It does not have a retained publication
-
A topic with a retained publication results from a publisher putting a message to a topic with the option
MQPMO_RETAIN.Use the runmqsc command
DISPLAY TPSTATUS('USA/Alabama') RETAINEDto check if USA/Alabama has a retained publication. The response isYESorNO.Use the runmqsc command
CLEAR TOPICSTR('USA/Alabama') CLTRTYPE(RETAINED)to remove a retained publication from USA/Alabama. - It has no child topics
-
USA/Alabama/Auburn is a topic with no child topics. USA/Alabama/Auburn is the direct child topic of USA/Alabama.
Display the direct children of USA/Alabama with the runmqsc command
DISPLAY TPSTATUS('USA/Alabama/+'). - There are no active publishers to the node
-
An active publisher to a node is an application that has the topic open for output.
For example, an application opens the topic object named Alabama with open options
MQOO_OUTPUT.To display active publishers to USA/Alabama and all its children, use the runmqsc command
DISPLAY TPSTATUS('USA/Alabama/#') TYPE(PUB) ACTCONN. - There are no active subscribers to the node
-
An active subscriber can either be a durable subscription, or an application that has registered a subscription to a topic with MQSUB, and not closed it.
To display active subscriptions to USA/Alabama, use the runmqsc command
DISPLAY TPSTATUS('USA/Alabama') TYPE(SUB) ACTCONN.To display active subscriptions to USA/Alabama and all its children, use the runmqsc command
DISPLAY TPSTATUS('USA/Alabama/#') TYPE(SUB) ACTCONN.
Managing the number of topics in a topic tree
In summary, there are a number of ways to manage the number of topics in a topic tree.- Display TPCOUNT
- Use the runmqsc command
DISPLAY PUBSUB ALLperiodically to display the TPCOUNT property. This is the number of topic nodes in the topic tree. If the number is growing it might indicate that a shorter TREELIFE is required, or that a redesign of the topics themselves is required. - Modify TREELIFE
- An unused topic has a lifetime of 30 minutes by default. You can make the lifetime of an unused topic smaller.
- Exceptionally, restart the queue manager
- When the queue manager is restarted, the topic tree is reinitialized from topic objects, nodes with retained publications, and durable subscriptions. Topics that had been created by the operation of publisher and subscriber programs are eliminated.