Skip to content

Redshift CPU utilisation very high on running COPY JOB

0

We have been using Redshift ra3.large type instance. We were ingesting data into the redshift via COPY JOB in redshift from S3. Suddenly, from the last few hours the CPU utilisation keeps hovering around more than 97%. There are no active queries running on the cluster and its a single node Redshift cluster. The Redshift storage is around 70% full, but I don't think that is a reason for the CPU spike. We even tried rebooting the Redshift but that did not solve the CPU issue. Also, there has been no change in the amount of data ingestion or processing.
What could be the reason of this sudden CPU spike
Enter image description here

We tried figuring out the queries taking the most CPU and found few of these. This looks like something related to COPY JOB which is handled internally by AWS and I don't think we have control over this.

select stq.userid, stq.query, trim(stq.label) as label, stq.xid, stq.pid, svq.service_class,
query_cpu_usage_percent as "cpu_%",starttime, endtime, datediff(s,starttime, endtime) as duration_s,
substring(stq.querytxt,1,500) as querytext from stl_query stq
join svl_query_metrics svq on stq.query=svq.query 
where query_cpu_usage_percent is not null and starttime > sysdate - 1
order by query_cpu_usage_percent desc;

Enter image description here

1 Answer
0

Hello

There may be several reasons for the CPU usage to grow. Here are a few steps to help you diagnose the issue:

Troubleshooting High CPU During Redshift COPY Operations

High CPU usage can occur during Amazon Redshift COPY processes because these are CPU-intensive, primarily due to several pre-ingestion steps:

  • The COPY command analyzes compression, scans, sorts, and aggregates the data before insertion.
  • By default, these tasks execute sequentially, potentially causing the CPU to reach maximum capacity.
  • Performance may worsen as the volume of data grows.

To identify specific causes:

  • Use Redshift Advisor's suggested SQL queries to check for overhead from compression analysis.
  • Monitor node-level CPUUtilization metrics in CloudWatch.
  • Run queries to diagnose performance bottlenecks.
  • Look for data skew or distribution issues leading to uneven node workloads:
  •     [(https://docs.aws.amazon.com/redshift/latest/dg/advisor-recommendations.html)] 
    
  •     [(https://aws.amazon.com/blogs/big-data/enhance-data-ingestion-performance-in-amazon-redshift-with-concurrent-inserts/)].
    
  •     This repost topic:  high-cpu-usage-of-one-redshift-node-not-leader-how-understand-what-is-causing-this-imbalance
    

Improving COPY Performance To enhance efficiency and lower CPU load during COPY:

  1. Bypass compression analysis:
  • Explicitly set column ENCODE options when creating tables.
  • Add COMPUPDATE OFF to COPY commands.
  • Automate encoding using AWSColumnEncodingUtility from GitHub.
  1. Optimize file management:
  • Break large data uploads into smaller batches.
  • Use multiple files for loading (preferably as many as the Redshift slices).
  • Compress files before upload and aim for file sizes between 1MB–1GB.
  • For bulk loads, leverage ManifestGenerator or similar tools.
  1. Leverage concurrent insert functionality:
  • Ensure your cluster is on patch 187 or later to take advantage of concurrent inserts.
  • Note potential deadlock risks with multiple simultaneous COPY operations
  •    [(https://docs.aws.amazon.com/redshift/latest/dg/advisor-recommendations.html)] 
    
  •     This repost topic : improve-copy-ingestion-performance-for-large-data-loads-on-amazon-redshift
    
  •     [(https://aws.amazon.com/blogs/big-data/enhance-data-ingestion-performance-in-amazon-redshift-with-concurrent-inserts/].
    

Monitoring and Diagnostic Queries

Find tables with missing statistics:

SELECT substring(trim(plannode),1,100) AS plannode, count(*) 
FROM stl_explain 
WHERE plannode LIKE '%missing statistics%' 
GROUP BY plannode 
ORDER BY 2 DESC;

Identify data skew or unsorted rows:

-- See source for full query
SELECT trim(pgn.nspname) AS schema, 
trim(a.name) AS table, id AS tableid,
-- Additional columns omitted for brevity
FROM stv_tbl_perm a
-- Joins omitted for brevity
WHERE mbytes IS NOT NULL 
ORDER BY mbytes DESC;

Find longest running queries:

-- See source for full query
SELECT trim(database) AS db, count(query) AS n_qry,
-- Additional columns omitted for brevity
FROM (SELECT userid, label, stl_query.query,
-- Subquery omitted for brevity
GROUP BY database, label, qry_md5, aborted
ORDER BY total DESC LIMIT 50;

[[repost article on diagnosing queries](https://repost.aws/articles/ARxvwkh0OWTfiUFXdT-qnjwg/redshift-diagnostics-queries-to-identify-the-performance-bottleneck]

[repost article on cpu usage]

Hope this helps!

AWS

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.