Commit b65824d9 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Adding throttle test.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@7427 b35dd754-fafc-0310-a699-88a17e54d16e
parent abf8d3fd
<?xml version="1.0" encoding="UTF-8"?>
<module version="4" relativePaths="true" type="JAVA_MODULE">
<component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/build/lib/smack.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/build/lib/smackx.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntryProperties />
</component>
</module>
This diff is collapsed.
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.test.throttle;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.packet.Time;
import java.util.Calendar;
import java.util.concurrent.atomic.AtomicInteger;
/**
* A simple client to test XMPP server throttling. When server throttling is working
* properly, a server should slow down incoming packets to match the speed of outgoing
* packets (otherwise, memory would fill up until a server crash).<p/>
*
* This client should be deployed as follows:
* <pre>
* [ writer ] -- fast connection --> [ xmpp server ] -- slow connection --> reader
* </pre>
*
* A good way to simulate fast and slow connections is to use virtual machines where
* the network interface speed can be set (to simulate a modem, etc).
*
* java ThrottleTestReader [server] [username] [password]
*
* @author Matt Tucker
*/
public class ThrottleTestReader {
private static AtomicInteger packetCount = new AtomicInteger(0);
private static boolean done = false;
/**
* Starts the throttle test reader client.
*
* @param args application arguments.
*/
public static void main(String [] args) {
if (args.length != 3) {
System.out.println("Usage: java ThrottleTestReader [server] [username] [password]");
System.exit(0);
}
String server = args[0];
String username = args[1];
String password = args[2];
try {
// Connect to the server, without TLS encryption.
ConnectionConfiguration config = new ConnectionConfiguration(server);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
XMPPConnection con = new XMPPConnection(config);
System.out.print("Connecting to " + server + "... ");
con.connect();
con.login(username, password, "reader");
System.out.print("success.");
System.out.println("");
// Get the "real" server address.
server = con.getServiceName();
String writerAddress = username + "@" + server + "/writer";
String readerAddress = username + "@" + server + "/reader";
System.out.println("Registered as " + readerAddress);
// Look for the reader process.
System.out.print("Waiting for " + writerAddress + "...");
PacketCollector collector = con.createPacketCollector(new AndFilter(
new FromMatchesFilter(writerAddress), new PacketTypeFilter(Time.class)));
Time timeRequest = (Time)collector.nextResult();
Time timeReply = new Time(Calendar.getInstance());
timeReply.setPacketID(timeRequest.getPacketID());
timeReply.setType(IQ.Type.RESULT);
timeReply.setTo(timeRequest.getFrom());
con.sendPacket(timeReply);
System.out.println(" found writer. Now in reading mode.");
// Track how many packets we've read.
con.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
packetCount.getAndIncrement();
}
}, new PacketTypeFilter(Message.class));
while (!done) {
Thread.sleep(5000);
int count = packetCount.getAndSet(0);
System.out.println("Packets per second: " + (count/5));
}
// Sleep while we're reading packets.
Thread.sleep(Integer.MAX_VALUE);
}
catch (Exception e) {
System.out.println("\nError: " + e.getMessage());
}
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.test.throttle;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.packet.Time;
/**
* A simple client to test XMPP server throttling. When server throttling is working
* properly, a server should slow down incoming packets to match the speed of outgoing
* packets (otherwise, memory would fill up until a server crash).<p/>
*
* This client should be deployed as follows:
* <pre>
* [ writer ] -- fast connection --> [ xmpp server ] -- slow connection --> reader
* </pre>
*
* A good way to simulate fast and slow connections is to use virtual machines where
* the network interface speed can be set (to simulate a modem, etc).
*
* java ThrottleTestWriter [server] [username] [password]
*
* @author Matt Tucker
*/
public class ThrottleTestWriter {
/**
* Starts the throttle test write client.
*
* @param args application arguments.
*/
public static void main(String [] args) {
if (args.length != 3) {
System.out.println("Usage: java ThrottleTestWriter [server] [username] [password]");
System.exit(0);
}
String server = args[0];
String username = args[1];
String password = args[2];
try {
// Connect to the server, without TLS encryption.
ConnectionConfiguration config = new ConnectionConfiguration(server);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
XMPPConnection con = new XMPPConnection(config);
System.out.print("Connecting to " + server + "... ");
con.connect();
con.login(username, password, "writer");
System.out.print("success.");
System.out.println("");
// Get the "real" server address.
server = con.getServiceName();
String writerAddress = username + "@" + server + "/writer";
String readerAddress = username + "@" + server + "/reader";
System.out.println("Registered as " + writerAddress);
// Look for the reader process.
System.out.print("Looking for " + readerAddress + "...");
while (true) {
IQ testIQ = new Time();
testIQ.setType(IQ.Type.GET);
testIQ.setTo(readerAddress);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(testIQ.getPacketID()));
con.sendPacket(testIQ);
// Wait 5 seconds.
long start = System.currentTimeMillis();
Packet result = collector.nextResult(5000);
collector.cancel();
// If we got a result, continue.
if (result != null && result.getError() == null) {
System.out.println(" found reader. Starting packet flood.");
break;
}
System.out.print(".");
long end = System.currentTimeMillis();
if (end - start < 5000) {
try {
Thread.sleep(5000 - (end-start));
}
catch (Exception e) {
// ignore.
}
}
}
// Found reader, now start flooding packets.
Message testMessage = new Message(readerAddress);
testMessage.setBody("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
while (true) {
con.sendPacket(testMessage);
}
}
catch (Exception e) {
System.out.println("\nError: " + e.getMessage());
e.printStackTrace();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment