(Code samples for this document can be downloaded here.)
You want to test the performance of calls in an environment - the unified schema XML API, SOAP API, eBay SDK for Java, or eBay SDK for .NET.
Write a performance test that captures the call start time just before you make the request, in both a timestamp and milliseconds, and the time immediately after the response is returned.
Run the performance test, with a call you choose, in the Sandbox first. Then, when you put the call into Production, capture similar timings in logs as your application runs.
The code sample that comes with this topic is written in Java for applications communicating with the SOAP API through the eBay SDK for Java.
Note: The sample included with this topic makes an initial call to GeteBayOfficialTime in the CallManager class, before it runs a performance test on another call such as AddItem or GetCategories. The initial GeteBayOfficialTime call is timed and its timing is displayed as output.
You need to capture timings on the line or lines of code that actually make the call to the eBay Web Services API. In Java, the specific line you want to time is this one (in this case, making an AddItem call):
// make the request
AddItemResponseType response = (AddItemResponseType)
call.executeByApiName("AddItem", request);
You need to take the start time after the request object is created and any necessary data (in this case, an ItemType) is added to the request. The start and end times are converted to milliseconds so that it is easy to calculate the difference. You should also format the time as a timestamp. If you need to contact eBay about a specific call timing, the timestamp allows eBay to research the call.
try {
// create the request object
System.out.println("[" + (new java.util.Date()).getTime() + " ms] " +
"-create new AddItemRequest ...");
AddItemRequestType request = new AddItemRequestType();
// set the item in the request
request.setItem(item);
// take start time before making the request
Date startTime = new java.util.Date();
// convert start time to milliseconds
long startTimeMS = startTime.getTime();
// format start time to display timestamp
Format formatter = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
String s = formatter.format(startTime);
System.out.println("startTime " + s + " [" + startTimeMS + " ms] " +
"-AddItemRequest - start");
// make the request
AddItemResponseType response = (AddItemResponseType)
call.executeByApiName("AddItem", request);
Then, take the end time immediately after you receive the response, and from it, calculate the execution time.
// make the request
AddItemResponseType response = (AddItemResponseType) call.executeByApiName("AddItem", request);
// take end time immediately
Date endTime = new java.util.Date();
long endTimeMS = endTime.getTime(); // convert endTime to milliseconds
long runTime = endTimeMS - startTimeMS;
String t = formatter.format(endTime); // format endTime for timestamp
System.out.println("endTime " + t + " [" + endTimeMS + " ms] " + "-AddItemRequest - end");
System.out.println("[Execution time] " + (runTime) + " ms");
times[i] = runTime;
Running this simple performance test should give output like this:
Starting item 0 [1128646884024 ms] -begin ... [1128646884024 ms] -build item ... [1128646884024 ms] -create new AddItemRequest ... startTime 2005.10.06 18:01:24 [1128646884024 ms] -AddItemRequest - start - Sending SOAP request to: https://api.sandbox.ebay.com/wsapi?siteid=0 &callname=AddItem&client=java&appid=INDEPENDENV14L9185124FNLW855JL - HTTP Compression: send gzip request... - HTTP Compression - gzip decompress response: ContentLength=585 endTime 2005.10.06 18:01:25 [1128646885539 ms] -AddItemRequest - end [Execution time] 1515 ms Starting item 1 [1128646885539 ms] -begin ... [1128646885539 ms] -build item ... [1128646885539 ms] -create new AddItemRequest ... startTime 2005.10.06 18:01:25 [1128646885539 ms] -AddItemRequest - start - Sending SOAP request to: https://api.sandbox.ebay.com/wsapi?siteid=0 &callname=AddItem&client=java&appid=INDEPENDENV14L9185124FNLW855JL - HTTP Compression: send gzip request... - HTTP Compression - gzip decompress response: ContentLength=585 endTime 2005.10.06 18:01:27 [1128646887133 ms] -AddItemRequest - end [Execution time] 1594 ms . .
If the performance test makes a number of requests to a certain call, like AddItem.java in the sample, it is useful to take an average of the call execution time. In AddItem.java, this is done by storing the execution times in an array, then taking the average of the values.
int index = 50; // number of calls to AddItem
long[] times = new long[index]; // array to store times
.
.
// get the average of the listing times
long sum = 0;
for (int i=0; i<index; i++) {
sum = sum + times[i];
}
long avg = sum / index;
System.out.println("Average time for AddItem is " + avg + " ms");
When the calls complete, these lines display an average time like this:
Average time for AddItem is 936 ms
You can customize the simple example included with this topic to suit the needs of your application, or rewrite it for a different language or eBay development environment. Keep these guidelines in mind: