Smack behavior for multithreaded environment

Hi,

I have recently started using Smack 4.0.5 version as a client for my openfire server. I have just completed a basic implementation of (1) createAccount API using Smack (2)adding users to a particular roster and all my unit test cases passed. I then exposed this createAccount API as a restful interface.But just to check the performance . I ran a JMeter load test by spawning 1000 concurrent requests to create users in openfire. This is where the problem begins. , Although a lot of requests seems to be going through I started observing the following exceptions

org.jivesoftware.smack.SmackException$NoResponseException

at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:1 91)

at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:1 75)

at org.jivesoftware.smack.Roster.createEntry(Roster.java:316)

at com.hp.userservice.dao.impl.ProvisioningDAO.addUserToMerchantRoster(Provisionin gDAO.java:356)

at com.hp.userservice.dao.impl.UserServiceAdministrationImpl.createUser(UserServic eAdministrationImpl.java:90)

Connection closed with error

stream:error (conflict)

at org.jivesoftware.smack.tcp.PacketReader.parsePackets(PacketReader.java:226)

at org.jivesoftware.smack.tcp.PacketReader.access$000(PacketReader.java:47)

at org.jivesoftware.smack.tcp.PacketReader$1.run(PacketReader.java:81)

2014-11-12 13:25:36 INFO com.hp.userservice.dao.impl.ProvisioningDAO:157 - User created successfully in OF_USER table in openfire

Exception writing closing stream element

java.net.SocketException: Software caused connection abort: socket write error

at java.net.SocketOutputStream.socketWrite0(Native Method)

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)

at java.net.SocketOutputStream.write(SocketOutputStream.java:159)

at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)

at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)

at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)

at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)

at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)

at java.io.BufferedWriter.flush(BufferedWriter.java:254)

at org.jivesoftware.smack.tcp.PacketWriter.writePackets(PacketWriter.java:190)

at org.jivesoftware.smack.tcp.PacketWriter.access$000(PacketWriter.java:40)

at org.jivesoftware.smack.tcp.PacketWriter$1.run(PacketWriter.java:77)

These errors seems to be occurring even for 50 concurrent users.

This is my Code :

//Obtaining XMPPCOnnection

public XMPPConnection connectToOF() throws ConnectionFailedException{

configuration = new ConnectionConfiguration(OFHost, OFPort);

configuration.setSecurityMode(SecurityMode.disabled);

configuration.setReconnectionAllowed(true);

configuration.setSecurityMode(SecurityMode.disabled);

configuration.setRosterLoadedAtLogin(false);

configuration.setSendPresence(false);

connection = new XMPPTCPConnection(configuration);

try {

connection.connect();

return connection;

} catch (XMPPException | SmackException | IOException e) {

log.error(“Error while obtaining the connection to Openfire.”);

log.error(e.getMessage());

throw new ConnectionFailedException(ErrorCodes.OPENFIRE_SERVER_UNREACHABLE);

}

//Creating Account

AccountManager manager = connectionObj.getAccountManager();

Map<String, String> registrationMap = new HashMap<String, String>();

registrationMap.put(“name”, userObj.getAlias());

registrationMap.put(“email”, userObj.getEmailId());

try {

manager.createAccount(userName, password, registrationMap); //ofuser create account

}catch(Exception e){

}

//Roster Snippet

Roster roster = xmppconnection.getRoster();

String groupName = null;

if(userObj.getGroup() == null )

groupName = userObj.getAppid();

else

groupName = userObj.getGroup();

RosterGroup rgroup = roster.createGroup(groupName);

if(rgroup !=null)return true;

else

return false;

}

I need to know under what circumstances are the exceptions raised. Are there any performance benchmarks already available, Is there any particular configuration I need to do in my code to ensure such errors dont arise ?

NoResponseExceptions is self explanatory. And the reason for a stream error of type ‘conflict’ can be found in the XMPP RFC: Extensible Messaging and Presence Protocol (XMPP): Core

It bet your problems come because you re-use the same fullJID, i.e. the same bareJID and resource, for the connections.

Hi,

Thanks for your response. I have also tried modifying the resource by adding an AtomicIntegers to the resourceIdentifier and yet the same exception occurs. the stream conflict seems to be reduced but the org.jivesoftware.smack.SmackException$NoResponseException still continues.

Thanks for the help. I really appreciate it.

Thanks

Raveesh