← Load Test Directory

XML-RPC Load Testing

Use LoadForge to seamlessly test XML-RPC servers using the powerful capabilities of Python.

You are now browsing the LoadForge locust test directory. You can use these tests as a starting point for your own tests, or use our AI wizard to generate one automatically.

World

Overview

By default, LoadForge is set to test plain HTTP/HTTPS websites. But its versatility allows users to venture beyond this norm. If you're looking to load test an XML-RPC server, LoadForge combined with Python provides a simple and effective way. This documentation walks you through how to achieve that.

Key Concepts

XML-RPC stands for "XML Remote Procedure Call". It's a protocol that encodes its calls as XML and transmits via HTTP. It allows for data to be passed, processed, and returned.

LoadForge is a platform that offers a straightforward way to create load tests using Python scripts, such as those that define interactions with XML-RPC servers.

Testing XML-RPC Servers

Below is a practical example of how you can customize LoadForge to test an XML-RPC server. This script simulates calls to the get_time() and get_random_number() functions. Replace these calls with those relevant to your XML-RPC service.

Code Example:

import time
from xmlrpc.client import ServerProxy, Fault
from locust import User, task

class XmlRpcClient(ServerProxy):
    """
    XmlRpcClient is a tailored version of the standard library's ServerProxy.
    It captures function calls and triggers the *request* event upon completion, ensuring the calls are logged.
    """

    def __init__(self, host, request_event):
        super().__init__(host)
        self._request_event = request_event

    def __getattr__(self, name):
        func = ServerProxy.__getattr__(self, name)

        def wrapper(*args, **kwargs):
            start_time = time.perf_counter()
            request_meta = {
                "request_type": "xmlrpc",
                "name": name,
                "response_length": 0,
                "response": None,
                "context": {},  # Refer to HttpUser for context implementation details
                "exception": None,
            }
            try:
                request_meta["response"] = func(*args, **kwargs)
            except Fault as e:
                request_meta["exception"] = e
            request_meta["response_time"] = (time.perf_counter() - start_time) * 1000
            self._request_event.fire(**request_meta)  # Logging the request
            return request_meta["response"]

        return wrapper

class XmlRpcUser(User):
    abstract = True  # Ensures that this isn't instantiated as an actual user

    def __init__(self, environment):
        super().__init__(environment)
        self.client = XmlRpcClient(self.host, request_event=environment.events.request)

# The user class that is instantiated for testing
class MyUser(XmlRpcUser):
    @task
    def get_time(self):
        self.client.get_time()

    @task
    def get_random_number(self):
        self.client.get_random_number(0, 100)

Locust Test Compatibility

LoadForge is built on the backbone of Locust, making it compatible with open-source Locust scripts. If you're already a Locust user, you can effortlessly port your scripts to LoadForge to amplify your testing capabilities.

Ready to run your test?
Launch your locust test at scale.