Increase server CPU utilization
PelicanDT lets you simulate a test environment with high CPU utilization. This helps you test whether your application runs correctly under these conditions. This topic describes how to use PelicanDT to increase server CPU utilization.
Prerequisites
The PelicanDT SDK is installed. For more information, see Install the PelicanDT SDK.
Your application is running on a remote Linux server.
Procedure
This example shows how to simulate an environment with 70% CPU utilization for 3 minutes.
Add the following code to your project and configure it as follows:
In the code, enter the IP address, username, and logon password for your remote server.
Set the CPU utilization to 70% and the duration to 3 minutes.
import com.alibaba.pelican.chaos.client.RemoteCmdClientConfig; import com.alibaba.pelican.chaos.client.impl.RemoteCmdClient; import com.alibaba.pelican.chaos.client.utils.CpuUtils; /** * @author moyun@middleware */ public class DemoCPU { public static void main(String[] args) { // The IP address of the remote server. String ip = ""; // The username for the remote server. String userName = ""; // The logon password for the remote server. String password = ""; RemoteCmdClientConfig config = new RemoteCmdClientConfig(); config.setIp(ip); config.setUserName(userName); config.setPassword(password); RemoteCmdClient client = new RemoteCmdClient(config); // Set the CPU utilization percentage. int percent = 70; // Set the duration. int delayMinutes = 3; // Increase the CPU utilization. CpuUtils.adjustCpuUsage(client, percent, delayMinutes); } }Run your project.
Verify the results
You can view the CPU monitoring data in the ECS console. For more information, see View instance information on the instance details page.