Topic lifetime/unsubscribe

150 views
Skip to first unread message

David Heidrich

unread,
Oct 19, 2012, 9:03:08 AM10/19/12
to haze...@googlegroups.com
Hey,
I'm using hazelcast to implement a clustered Atmosphere (Websocket, Comet) Chat-Application. My application will produce a lot of different topics (each chat has a unique id where messages are published).
As I see in Hazelcast Management Console, my list of Topics grow and old Topic's (that might have no subscribers) are not deleted. I think this will yield in memory error's in the near future :).

Is there anything that will prevent this behavior; Like a Timeout if a Topic has no subscribers?
David

Peter Veentjer

unread,
Oct 19, 2012, 9:16:17 AM10/19/12
to haze...@googlegroups.com
AFAIK there is no garbage collection mechanism available for the topic.

So I guess the thing you can do is
1) get hold of the itopics. Perhaps store the names of the topic in
hazelcast, e.g. in a map, when the topic is created.
2) walk over the topics periodically
3) determine if a topic is unused (easier said then done). Perhaps you
can have a look at the getLocalTopicStats() and determine 'stale'
based on change in number of receives messages. If there is no change
for example 30 minutes, then the Topic could be seen as dead. See
http://www.hazelcast.com/javadoc/com/hazelcast/impl/monitor/LocalTopicOperationStatsImpl.html
4) destroy the instance when marked as dead.
> --
> You received this message because you are subscribed to the Google Groups
> "Hazelcast" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hazelcast/-/pdy7bRGEIX4J.
> To post to this group, send email to haze...@googlegroups.com.
> To unsubscribe from this group, send email to
> hazelcast+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hazelcast?hl=en.

David Heidrich

unread,
Oct 19, 2012, 9:45:57 AM10/19/12
to haze...@googlegroups.com
Thank you, think it will be very complicated :/

"getLocalTopicStats" will only return stats for my specific Cluster i call this method on, or? So I can never be sure that other nodes may still active.
And destroy will "kill" this topic on the whole cluster.

Peter Veentjer

unread,
Oct 19, 2012, 9:59:43 AM10/19/12
to haze...@googlegroups.com
On Fri, Oct 19, 2012 at 4:45 PM, David Heidrich <m...@bowlingx.com> wrote:
> Thank you, think it will be very complicated :/
>
> "getLocalTopicStats" will only return stats for my specific Cluster i call
> this method on, or?

I guess so.

But that should not be the end of the world. You still can still let
each member iterate over all topics and read out the local stats. They
need to compare the previous stats with the new stats, if there is no
change. then the next topic is checked. If there is a change, you
publish some 'last updated' timestamp in a hazelcast map (so key:
topic.name, and value: last updated timestamp.

And then in another process you iterate over this map, and see which
topics have an expired timestamp.

Perhaps someone else can come up with a simpler solution.
> https://groups.google.com/d/msg/hazelcast/-/MBbdnju8OjIJ.

David Heidrich

unread,
Oct 19, 2012, 10:06:15 AM10/19/12
to haze...@googlegroups.com
Yeah, that timestamp thing might be a solution :). Think I will try
this. Thank you!

2012/10/19 Peter Veentjer <alarm...@gmail.com>:

Enes Akar

unread,
Oct 19, 2012, 12:24:55 PM10/19/12
to haze...@googlegroups.com
That may be another solution:

- Create a map named 'topicEvictionMap'. That will store topics' names as keys.
- On configuration set time-to-live-seconds 6 hours for this map. (as records to be evicted in 6 hours if not updated)
- Add a messageListener for each topic. onMessage() method update topicEvictionMap. (you can set current time or any different value: topicEvictionMap.put(topicName, System.currentTimeInMillis); )
- At each hour, traverse topic names, check whether its name exists in topicEvictionMap. If it does not exist you can destroy it.
--
Enes Akar
Hazelcast | Open source in-memory data grid
Mobile: +90.505.394.1668

Reply all
Reply to author
Forward
0 new messages