Part 3: Load testing SAP with JCo

Part 3: Load testing SAP with JCo

This utility provides a very simple load testing application. Load testing SAP using RFC connections gives you a good idea of how SAP would perform under a specific load by your application. The code itself is a multi-threaded utility that allows you to specify the number of threads (connections) that you want to test SAP with. After creation, each thread creates a connection to SAP then enters an infinite loop, with each loop executing a single RFC call to SAP.
import com.sap.mw.JCo.*;

public class SAPLoadTest extends Thread {

    static final String[][] sapParams = { { "client", "000" }, 
{ "user", "myUsername" }, { "passwd", "myPassword" }, { "lang", "en" }, 
{ "ashost", "mySapHost" }, { "sysnr", "00" } };
    static final int maxConnections = 100; //Number of threads
    static int count = 0;
    static int maxThread = 0;
    static JCo.Function function;

    public SAPLoadTest() {
        super("" + ++count);
        start();
    }
    public void run() {
        JCo.Client threadConn = null;
        try {
            threadConn = JCo.createClient(sapParams);
            threadConn.connect();
        } catch (Exception pEx) {
            pEx.printStackTrace();
        }
        for (int i = 0; true; i++) {
            try {
                threadConn.execute(function);
                if (maxThread < new Integer(getName()).intValue()) {
                    maxThread = new Integer(getName()).intValue();
                    System.out.println(maxThread);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        JCo.Client connection = JCo.createClient(sapParams);
        connection.connect();
        IRepository repository = new JCo.Repository("SAPRep", connection);
        IFunctionTemplate functionTempl = repository
                .getFunctionTemplate("RFC_SYSTEM_INFO");
        function = functionTempl.getFunction();
        connection.disconnect();
        for (int i = 0; i < maxConnections; i++) {
            new SAPLoadTest();
        }
    }
}
Bear in mind, any create/update RFC/BAPI will continue to modify the system until the application is manually terminated.

THE JCO UTILITY COOKBOOK

 Home: Introduction
 Part 1: Writing an RFC structure to XML
 Part 2: Generating metadata for an RFC structure
 Part 3: Load testing SAP with JCo
 Part 4: Creating a serialized RFC interface
 Review: Conclusion and more resources

This was first published in August 2005