Smack Pubsub has high latency in listener response

Hi, I have a Smack PubSub client program which is functionally running well on android smartphones.

However, there is an issue with the latency in response. I have a smartphone (Android version 5.0.2) which consistently receives the publishing item within seconds. But I have other 2 smartphones (Android 6.0.1) which consistently receive the publishing item from server within 1-2 minutes after the client has sent the publish item to openfire server. I tried to change the compileSdkVersion to 23 to match with Android 6 smartphone, the latency is still as long.

Note that I am using ChatMessageListener to listen and parse for PubSub response, I can see response in StanzaListener is almost instantaneous, but not in ChatMessageListener which takes 1-2 minutes to happen.

I have search around for solution but could not find any. Any help is highly appreciated.

This behavior typically occurs if you perform a long running or blocking operation in a synchronous stanza listener, which, in turn, will delay the whole processing chain of the connection.

Thanks for quick reply!

Originally I set connection.addAsyncStanzaListener(listener, filter). Now I tried to comment off this line to disable the StanzaListener. The response in ChatMessageListener is still as slow. Any other possibilities that can cause this behavior?

That adds an asynchronous stanza listener, which shouldn’t cause any problem.

Yep, I can think of plenty causes.

I have number of Listeners that are running. I can remove those Listeners 1 by 1 to identify which causes the latency.

Or do you have any other typical ways to solve this issue?

Hi I have removed the Listeners I have in the program, but it does not improve ChatMessageListener response. Could you list some of the possible causes?

I have found the answer to the issue. I have unknowingly subscribed the PubSub user to server node multiple times. And every subscription creates a new entry in the XML. This takes up the bandwidth to publish the data stream from server.

So it is important to put in a check before subscription to avoid multiple subscriptions which can slow down the publication.