Part 3: Load testing SAP with JCo

Working with SAP's Java Connector, JCo? Then you should check out this collection of handy utilities for working with RFC/BAPI interfaces when doing development with JCo. These truly are development utilities in the sense that their intent is to provide generic support for almost any programming effort that utilizes JCo to interface with SAP.

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 last published in August 2005

Dig Deeper on SAP ABAP

PRO+

Content

Find more PRO+ content and other member only offers, here.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close