OKP4 Gas Consumption Relevancy in Relation with CPU

HashKey Cloud
4 min readApr 13, 2023

1. Introduction to test report

This test is designed to test the relationship between OKP4 v4.1.0 gas consumption and server CPU usage. This test uses a script to call the OKP4-objectarium contract for stress testing, and monitors the server memory usage through Prometheus. The test results show that as the gas consumption increases, the CPU usage also increases. That is, there is a positive correlation between server memory usage and OKP4 gas consumption

2. Test environment

2.1 Hardware configuration

  • CPU: 4 cores
  • Memory: 8GB
  • Hard disk: 400GB

2.2 Software Configuration

  • OKP4d v4.1.0
  • Golang version go1.19.2 linux/amd64

3. Design test cases

3.1 Create a large number of non-zero addresses

Setting the sequence value in the OKP4 transaction is a mechanism to ensure that the transaction will not be repeatedly broadcast or replayed. In addition, it can also be used to protect blockchain networks from network congestion attacks. Therefore, a certain number of non-zero addresses are required to simultaneously call the OKP4-objectarium contracts to complete the stress test. Use okp4d keys add walletName -keyring-backend test to create an address without entering a password. After the address is created, a certain amount of $KNOWneeds to be sent as gas for calling the OKP4-objectarium contract. The specific script is as follows:

3.2 Call the OKP4-objectarium Contract

The OKP4-objectariumsmart contract enables the storage of arbitrary objectsin any Cosmos blockchains using the CosmWasm framework. Objects stored in the OKP4-objectarium smart contract cannot be stored data, so each contract call needs to generate a new object. The specific script is as follows:

4. Execute the Test Case

At the block height of 1,750,419, the transaction calling the OKP4-objectarium smart contract is sent for 7 minutes, and the program sleeps for 7 seconds after each transaction is sent, simulating the situation that the transaction volume is small. The reason why the program chooses to sleep for 7 seconds is that the exit of the OKP4 blockchain is about 7 seconds. Doing this test can eliminate the impact of the test program on the CPU usage. It can be seen from the figure that when the OKP4 program is running smoothly, about 23.2% of the total CPU is used on average; and when sending a transaction every 7 seconds on average, the average CPU usage is always maintained at 28%, without obvious fluctuations.

Figure 1 CPU usage when sending a transaction every 7 seconds

Table 1 Statistical Table of Gas and CPU Usage When Sending a Transaction Every 7 Seconds

At the block height of 1,752,868, the transaction calling the the OKP4-objectarium smart contract is sent, and the program sleeps for 0.3 seconds after each transaction is sent, simulating the situation where the transaction volume is moderate. According to the test results, the initial CPU usage is maintained at about 23%, and with the increase of transactions, the CPU usage increases to 35%.

Figure 2 CPU usage when sending a transaction every 0.3 seconds

Table 2 Statistical Table of Gas and CPU Usage When Sending a Transaction Every 0.3 Seconds

At the block height of 1,740,441, batches of transactions calling the OKP4-objectarium smart contract are sent for 7 minutes, and there is no restriction on the transaction speed. The figure below shows the CPU usage of the cloud server before and after the test. It can be seen from the figure that when the OKP4 program is running smoothly, 23.2% of the total CPU is used on average. As the transactions increase, the CPU usage gradually increases until the CPU usage reaches about 54%.

Figure 2 CPU usage when sending a transaction every 0.3 seconds

Table3 Gas and CPU Usage Statistics When the Transaction Sending Speed is Unlimited

5. Summary

According to the test results, the following conclusions can be drawn:

  • Sending batch transactions calling the OKP4-objectarium smart contract can result in an increased CPU usage. This is because batch operations consume a lot of CPU resources;
  • When the transactions increase, the CPU usage gradually increases. This is because processing more transactions requires more computing resources to ensure the normal completion of transactions;
  • During the test period, when the transactions reached a certain threshold, the CPU usage tends to be stable at around 54%. This may mean that the script calling the OKP4-objectarium smart contract has reached a performance bottleneck or the OKP4 blockchain has reached a performance bottleneck.

--

--

HashKey Cloud

A staking services platform focusing on public chains built upon the likes of PoS and DPoS.