Search in sources :

Example 1 with DefaultSmppClient

use of com.cloudhopper.smpp.impl.DefaultSmppClient in project smscgateway by RestComm.

the class Client method test.

private void test(String[] args) throws Exception {
    this.sessionCount = Integer.parseInt(args[0]);
    this.windowSize = Integer.parseInt(args[1]);
    this.submitToSend = Integer.parseInt(args[2]);
    this.rateLimiter = Integer.parseInt(args[3]);
    this.startDestNumber = Long.parseLong(args[4]);
    this.destNumberDiff = Integer.parseInt(args[5]);
    this.sourceNumber = args[6];
    this.peerAddress = args[7];
    this.peerPort = Integer.parseInt(args[8]);
    this.systemId = args[9];
    this.password = args[10];
    message = args[11];
    esmClass = Integer.parseInt(args[12]);
    if (sessionCount < 1) {
        throw new Exception("Session count cannot be less than 1");
    }
    if (windowSize < 1) {
        throw new Exception("Windows size cannot be less than 1");
    }
    if (submitToSend < 1) {
        throw new Exception("Submit to send cannot be less than 1");
    }
    if (startDestNumber < 1) {
        throw new Exception("Start Destination Number cannot be less than 1");
    }
    if (destNumberDiff < 1) {
        throw new Exception("Destination Number difference cannot be less than 1");
    }
    if (this.sourceNumber == null || this.sourceNumber == "") {
        throw new Exception("Source Number cannot be null");
    }
    if (this.peerAddress == null || this.peerAddress == "") {
        throw new Exception("Peer address cannot be null");
    }
    if (this.peerPort < 1) {
        throw new Exception("Peer port cannot be less than 1");
    }
    if (this.message == null) {
        throw new Exception("Message cannot be less than 1");
    }
    this.endDestNumber = startDestNumber + destNumberDiff;
    logger.info("sessionCount=" + sessionCount);
    logger.info("windowSize=" + windowSize);
    logger.info("submitToSend=" + submitToSend);
    logger.info("startDestNumber=" + startDestNumber);
    logger.info("destNumberDiff=" + destNumberDiff);
    logger.info("endDestNumber=" + endDestNumber);
    logger.info("sourceNumber=" + sourceNumber);
    logger.info("peerAddress=" + peerAddress);
    logger.info("peerPort=" + peerPort);
    logger.info("systemId=" + systemId);
    logger.info("password=" + password);
    logger.info("message=" + message);
    logger.info("rateLimiter=" + rateLimiter + " sms/sec");
    // rate
    this.rateLimiterObj = RateLimiter.create(this.rateLimiter);
    // lastThrottledMessageTime = null;
    // 
    // setup 3 things required for any session we plan on creating
    // 
    // for monitoring thread use, it's preferable to create your own
    // instance
    // of an executor with Executors.newCachedThreadPool() and cast it to
    // ThreadPoolExecutor
    // this permits exposing thinks like executor.getActiveCount() via JMX
    // possible
    // no point renaming the threads in a factory since underlying Netty
    // framework does not easily allow you to customize your thread names
    ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
    // to enable automatic expiration of requests, a second scheduled
    // executor
    // is required which is what a monitor task will be executed with - this
    // is probably a thread pool that can be shared with between all client
    // bootstraps
    ScheduledThreadPoolExecutor monitorExecutor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, new ThreadFactory() {

        private AtomicInteger sequence = new AtomicInteger(0);

        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName("SmppClientSessionWindowMonitorPool-" + sequence.getAndIncrement());
            return t;
        }
    });
    // a single instance of a client bootstrap can technically be shared
    // between any sessions that are created (a session can go to any
    // different
    // number of SMSCs) - each session created under
    // a client bootstrap will use the executor and monitorExecutor set
    // in its constructor - just be *very* careful with the
    // "expectedSessions"
    // value to make sure it matches the actual number of total concurrent
    // open sessions you plan on handling - the underlying netty library
    // used for NIO sockets essentially uses this value as the max number of
    // threads it will ever use, despite the "max pool size", etc. set on
    // the executor passed in here
    DefaultSmppClient clientBootstrap = new DefaultSmppClient(Executors.newCachedThreadPool(), this.sessionCount, monitorExecutor);
    // same configuration for each client runner
    SmppSessionConfiguration config = new SmppSessionConfiguration();
    config.setWindowSize(this.windowSize);
    config.setName("Tester.Session.0");
    config.setType(SmppBindType.TRANSCEIVER);
    // config.setHost("107.178.220.137");
    config.setHost(this.peerAddress);
    config.setPort(this.peerPort);
    config.setConnectTimeout(10000);
    config.setSystemId(this.systemId);
    config.setPassword(this.password);
    config.getLoggingOptions().setLogBytes(false);
    // to enable monitoring (request expiration)
    config.setRequestExpiryTimeout(30000);
    config.setWindowMonitorInterval(15000);
    config.setCountersEnabled(true);
    // config.setAddressRange("6666");
    // various latches used to signal when things are ready
    CountDownLatch allSessionsBoundSignal = new CountDownLatch(this.sessionCount);
    CountDownLatch startSendingSignal = new CountDownLatch(1);
    // create all session runners and executors to run them
    ThreadPoolExecutor taskExecutor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
    ClientSessionTask[] tasks = new ClientSessionTask[this.sessionCount];
    for (int i = 0; i < this.sessionCount; i++) {
        tasks[i] = new ClientSessionTask(allSessionsBoundSignal, startSendingSignal, clientBootstrap, config, this.submitToSend, this.rateLimiterObj);
        taskExecutor.submit(tasks[i]);
    }
    // wait for all sessions to bind
    logger.info("Waiting up to 7 seconds for all sessions to bind...");
    if (!allSessionsBoundSignal.await(7000, TimeUnit.MILLISECONDS)) {
        throw new Exception("One or more sessions were unable to bind, cancelling test");
    }
    logger.info("Sending signal to start test...");
    long startTimeMillis = System.currentTimeMillis();
    startSendingSignal.countDown();
    // wait for all tasks to finish
    taskExecutor.shutdown();
    taskExecutor.awaitTermination(3, TimeUnit.DAYS);
    long stopTimeMillis = System.currentTimeMillis();
    // did everything succeed?
    int actualSubmitSent = 0;
    int sessionFailures = 0;
    for (int i = 0; i < this.sessionCount; i++) {
        if (tasks[i].getCause() != null) {
            sessionFailures++;
            logger.error("Task #" + i + " failed with exception: " + tasks[i].getCause());
        } else {
            actualSubmitSent += tasks[i].getSubmitRequestSent();
        }
    }
    // actualSubmitSent -= throttledMessageCount.get();
    logger.info("Performance client finished:");
    logger.info("       Sessions: " + this.sessionCount);
    logger.info("    Window Size: " + this.windowSize);
    logger.info("Sessions Failed: " + sessionFailures);
    logger.info("           Time: " + (stopTimeMillis - startTimeMillis) + " ms");
    logger.info("  Target Submit: " + this.submitToSend);
    logger.info("  Actual Submit: " + actualSubmitSent);
    logger.info("  Throttled Message count: " + throttledMessageCount);
    double throughput = (double) actualSubmitSent / ((double) (stopTimeMillis - startTimeMillis) / (double) 1000);
    logger.info("     Throughput: " + DecimalUtil.toString(throughput, 3) + " per sec");
    for (int i = 0; i < this.sessionCount; i++) {
        if (tasks[i].session != null && tasks[i].session.hasCounters()) {
            logger.info(" Session " + i + ": submitSM " + tasks[i].session.getCounters().getTxSubmitSM());
        }
    }
    // this is required to not causing server to hang from non-daemon
    // threads
    // this also makes sure all open Channels are closed to I *think*
    logger.info("Shutting down client bootstrap and executors...");
    clientBootstrap.destroy();
    executor.shutdownNow();
    monitorExecutor.shutdownNow();
    logger.info("Done. Exiting");
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) SmppSessionConfiguration(com.cloudhopper.smpp.SmppSessionConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultSmppClient(com.cloudhopper.smpp.impl.DefaultSmppClient) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 2 with DefaultSmppClient

use of com.cloudhopper.smpp.impl.DefaultSmppClient in project smscgateway by RestComm.

the class SMPPInitializer method init.

@Override
public void init(GlobalContext ctx) throws Exception {
    DefaultSmppClient clientBootstrap = new DefaultSmppClient(Executors.newCachedThreadPool(), ctx.getIntegerProp("smppp.smppStack.sessionCount"), ctx.executor);
    // same configuration for each client runner
    SmppSessionConfiguration config = new SmppSessionConfiguration();
    config.setWindowSize(ctx.getIntegerProp("smppp.smppStack.windowSize"));
    config.setName(ctx.getProperty("smppp.smppStack.name"));
    config.setType(SmppBindType.valueOf(ctx.getProperty("smppp.smppStack.type")));
    config.setHost(ctx.getProperty("smppp.smppStack.host"));
    config.setPort(ctx.getIntegerProp("smppp.smppStack.port"));
    config.setConnectTimeout(ctx.getIntegerProp("smppp.smppStack.connectTimeout"));
    config.setSystemId(ctx.getProperty("smppp.smppStack.systemId"));
    config.setPassword(ctx.getProperty("smppp.smppStack.password"));
    config.getLoggingOptions().setLogBytes(Boolean.valueOf(ctx.getProperty("smppp.smppStack.logBytes")));
    // to enable monitoring (request expiration)
    config.setRequestExpiryTimeout(ctx.getIntegerProp("smppp.smppStack.requestExpiryTimeout"));
    config.setWindowMonitorInterval(ctx.getIntegerProp("smppp.smppStack.windowMonitorInterval"));
    config.setCountersEnabled(Boolean.valueOf(ctx.getProperty("smppp.smppStack.countersEnabled")));
    DefaultSmppSessionHandler sessionHandler = (DefaultSmppSessionHandler) ctx.scenario;
    List<SmppSession> sessionList = new ArrayList(ctx.getIntegerProp("smppp.smppStack.sessionCount"));
    for (int i = 0; i < ctx.getIntegerProp("smppp.smppStack.sessionCount"); i++) {
        sessionList.add(clientBootstrap.bind(config, sessionHandler));
    }
    ctx.data.put("SMPPSessionList", sessionList);
    CyclicCounter sessionCounter = new CyclicCounter(ctx.getIntegerProp("smppp.smppStack.sessionCount"));
    ctx.data.put("sessionCounter", sessionCounter);
    ctx.fsm.fire(GlobalEvent.ASSOCIATION_UP, ctx);
}
Also used : SmppSessionConfiguration(com.cloudhopper.smpp.SmppSessionConfiguration) SmppSession(com.cloudhopper.smpp.SmppSession) DefaultSmppClient(com.cloudhopper.smpp.impl.DefaultSmppClient) DefaultSmppSessionHandler(com.cloudhopper.smpp.impl.DefaultSmppSessionHandler) ArrayList(java.util.ArrayList)

Aggregations

SmppSessionConfiguration (com.cloudhopper.smpp.SmppSessionConfiguration)2 DefaultSmppClient (com.cloudhopper.smpp.impl.DefaultSmppClient)2 SmppSession (com.cloudhopper.smpp.SmppSession)1 DefaultSmppSessionHandler (com.cloudhopper.smpp.impl.DefaultSmppSessionHandler)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1