How i can implement throttling in following multiple session code, i will oblige if you update it.
StressTestRunner.class);
PropertyConfigurator.configure( "log4j.properties" );
logger.info("Logging Setup Done...");
StressClient sc1 = new StressClient(0, "test msg");
StressClient sc2 = new StressClient(1, "test msg");
StressClient sc3 = new StressClient(2, "test msg");
long lTimeAtStart = System.currentTimeMillis();
ExecutorService pool = Executors.newFixedThreadPool( 3 );
pool.execute( sc1 ); // start task1
pool.execute( sc2 ); // start task2
pool.execute( sc3 ); // start task3
pool.shutdown(); // shutdown worker threads
long lTimeAtEnd = System.currentTimeMillis();
long timetakeninsec = (lTimeAtEnd - lTimeAtStart) / 1000;
long throughput = (3 * 100)/timetakeninsec;
System.out.println("Time at start = " + lTimeAtStart );
System.out.println("Time at end = " + lTimeAtEnd);
System.out.println("Throughput = " + throughput);
System.out.println("Quitting ");
}//EO Main
/*********************************************************************************************/
public class StressClient implements Runnable
{
private static final String DEFAULT_PASSWORD = "test";
private static final String DEFAULT_SYSID = "test";
private static final String DEFAULT_SOURCEADDR = "111";
private static final String DEFAULT_HOST = "xx.xx.xx.xx";
private static final Integer DEFAULT_PORT = 2775;
private static final Long DEFAULT_TRANSACTIONTIMER = 2000L;
private static final Integer DEFAULT_PROCESSOR_DEGREE = 3;
private SMPPSession smppSession = new SMPPSession();
private int id;
private String message;
private Logger logger = Logger.getLogger(StressClient.class);
public StressClient(int id,String msg)
{
this.id = id;
smppSession.setPduProcessorDegree(DEFAULT_PROCESSOR_DEGREE);
smppSession.setTransactionTimer(DEFAULT_TRANSACTIONTIMER);
message=msg;
}
public void run()
{
try
{
smppSession.connectAndBind("xx.xx.xx.xx",
2775, BindType.BIND_TX, "ITDEV", "ITDEV", "ITV",
TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, null);
logger.info("Bound to " + DEFAULT_HOST + ":" + DEFAULT_PORT);
System.out.println("Bound to " + DEFAULT_HOST + ":" + DEFAULT_PORT);
FileInputStream fstream = new FileInputStream("test"+id+".txt");
DataInputStream in = new DataInputStream(fstream);
int counter = 0;
while (in.available() !=0)
{
//System.out.println("In thread "+index+"=="+in.readLine().trim() );
counter ++;
smppSession.submitShortMessage("CMT", TypeOfNumber.ALPHANUMERIC, NumberingPlanIndicator.UNKNOWN, DEFAULT_SOURCEADDR, TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.ISDN,
"92"+in.readLine().trim(), new ESMClass(), (byte)0, (byte)1,
null, null, new RegisteredDelivery(0), (byte)0,
DataCoding.newInstance((byte)0),(byte)0, message.getBytes());
System.out.println("Message sent");
if( counter%500 == 0)
{
System.out.println("Thread " + id + " sent " + counter + " messages");
}
}
} catch (Exception e) {
logger.error("Failed submit short message '" + message + "'", e);
e.printStackTrace();
}//EO run