Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Troubleshooting High CPU Usage

Updated on 2025-02-13 GMT+08:00

Description

CPU usage refers to the percentage of CPU time occupied when the system is running.

CPU usage includes the user-mode CPU time percentage and kernel-mode CPU time percentage.

  • User mode is the mode in which user programs are running.
  • Kernel mode is the mode in which OS management programs are running, including system calls, kernel threads, and interrupts.

When the CPU is full, services slow down.

Cause Analysis

There are three possible causes:

  • Sharp increase in active sessions
  • ECS underlying resource contention (non-dedicated instances)
  • Too many slow SQL statements

The following figure shows the troubleshooting methods for the three possible causes.

Figure 1 Cause analysis

Troubleshooting

  • Sharp increase in active connections

    Check whether the percentage of kernel-mode CPU time is greater than 20% or whether the Active Connections metric increases sharply.

    • Checking the percentage of kernel-mode CPU time

      On the Cloud Eye console, check the Kernel-mode CPU Time Percentage metric in the last one hour.

      If this metric is higher than 20%, there may be a large number of system calls or interrupts. In this case, a large number of processes are running in the system.

      NOTE:

      When the number of active connections exceeds the instance specifications, the system continuously switches the processes running in the CPU. The kernel program switches the CPU to different address spaces. As a result, the kernel-mode CPU time percentage increases.

    • Checking active connections

      On the Cloud Eye console, check whether the Active Connections metric surged at a certain time point within the last 24 hours or last 7 days.

      NOTE:

      In normal cases, the number of active sessions should be twice the number of vCPUs to maximize CPU usage.

  • ECS resource contention (non-dedicated instances)

    A rare cause for kernel-mode CPU time percentage greater than 20% is ECS resource contention. This mainly occurs in non-dedicated instances (including general-purpose and general-enhanced instances).

    Generally, the kernel-mode CPU time percentage of RDS for PostgreSQL instances is lower than 10%. If this percentage is greater than 10%, check whether it is caused by ECS resource contention. Contact customer service to confirm this problem.

  • Too many slow SQL statements

    RDS for PostgreSQL provides slow query logs. You can use these logs to locate the time-consuming SQL statements for further analysis. However, a slow SQL statement may also cause other SQL statements to run slowly, so you may find many slow SQL statements in the logs. It is hard to find the target SQL statement.

    In addition to slow SQL statements, there are some simple SQL statements that may cause abruptly high CPU usage in some cases (for example, cyclic execution in a transaction or a large number of concurrent executions).

    The following methods are recommended for tracing slow SQL statements:

    1. Use the pg_stat_statements extension to locate the SQL statements that cause high CPU usage. For details, see pg_stat_statements.
    2. Query the pg_stat_activity view to find the SQL statements that have been running for a long time.
      SELECT  *,    
      (now() - backend_start) AS proc_duration,    
      (now() - xact_start) AS xact_duration,  
       (now() - query_start) AS query_duration,   
       (now() - state_change) AS state_duration  
      FROM pg_stat_activity  
       WHERE pid<>pg_backend_pid()  
      ORDER BY state_duration DESC limit 10;
    3. Query the pg_stat_user_tables view to find the tables that are being scanned in full mode and the corresponding SQL statements.
      select * from pg_stat_user_tables order by seq_tup_read desc, seq_scan desc limit 10;
    4. Check whether there are any slow SQL statements based on the pg_stat_statements or pg_stat_activity view.
      NOTE:

      The pg_stat_statements extension must be installed first.

      Check for slow SQL statements based on pg_stat_statements:

      select * from pg_stat_statements where query like '%tablename%' order by shared_blks_hit + shared_blks_read desc;

      Check for slow SQL statements based on pg_stat_activity:

      select 
        *, 
        (now() - backend_start) AS proc_duration,
        (now() - xact_start) AS xact_duration,
        (now() - query_start) AS query_duration,
        (now() - state_change) AS state_duration 
      from pg_stat_activity
      where pid<>pg_backend_pid() and query like '%tablename%'
      ORDER BY state_duration DESC;

      These slow SQL statements are usually caused by a lack of indexes. As a result, too many buffer reads are executed, consuming a large number of CPU resources.

Solution

  • Sharp increase in active connections

    Check whether the sharp increase in active connections is necessary for your workload. If yes, upgrade the instance specifications. If no, optimize the workload to address the sharp increase. You can also kill unnecessary sessions to reduce the CPU usage. For details, see Killing Sessions.

    NOTE:

    Killing a session may cause service disconnection. Your applications should be able to reconnect to the instance.

  • ECS resource contention (non-dedicated instances)

    Change your instance to a dedicated instance.

  • Too many slow SQL statements

    Locate the problematic SQL statements and optimize them.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback