RDS optimization?

Do you guys have any tips on optimizing RDS? I’m running it on a woocommerce setup and my cpu is hitting 100% at least once a day. Do you know any good companies that can help with this?

Usually any sort of APM will help with this, like NewRelic, Datadog, AppDynamics. They can tell you if you have some slow queries and stuff

Likely bad queries or missing indexes.

Depending on engine you’re running and the size of the instance, you can use RDS Performance Insights which gives you a graphical representation of the database load and you can drill down to specific queries which are using excessive CPU, I/O, etc.

https://aws.amazon.com/rds/performance-insights/

Performance insights to examine queries by load per database event was very helpful

it can help you see problematic queries which may not inherently seem problematic based on their simplicity but for which data volume or indices negatively impacts query performance

so if for example you have a query like “select * from table” for which the vast majority of the event load is dedicated to the sql handler (as compared to other queries) perhaps there is an opportunity to optimize the query or table

I personally haven’t found enhanced monitoring to be all that useful but in the moment if you want to visualize your current system memory side by side with mytop or current processlist, or slow query log that can be very helpful

also enable slow query log with a reasonable amount of query time (usually set to a timeout value like 30s but it may be beneficial to set it to 15s or lower if you aren’t catching the queries you’re looking for)

It’s likely not specifically RDS, but the underlying database (mysql, postgresql, etc) and queries being run against it.

I would also say that it’s (probably) totally appropriate for a DB to hit 100% CPU sometimes (depending on the workload and situation) because that means you’re not over-provisioned, so long as it’s not causing issues upstream (if the app layer is able to respond in time etc). If you’re maxing out the CPU and everything needing that DB grinds to a halt, then yeah it’s an issue.

Good suggestions here. Cloudwatch can also be used in a similar (but more barebones IMO) way to Newrelic, etc.

I don’t have any specific recommendations for companies that do that sort of thing, but an experienced developer or DBA would probably go a long way if the issue does need addressing.

If it’s happening around the same time it’s likely you have some kind of summary report that is hammering the DB.

Increase instance size? Switch to Aurora with many read replicas? Get off WooConmerece?

You’re gonna troubleshoot 3rd party code this way?

look at the enhanced statistics and figure out what query is doing this

basically do normal DBA work

This. There is SSMS for mssql, pg_stat_statement extension for postgresql probably something for oracle and mysql. There is log readers etc etc.. Find badly behaving queries, add indexes, do maintenance., shuffle jobs around. and it is ok to have 100% cpu for a while during day long as you dont drop too much traffic. If you do , consider adding more power.

pg stat statement is so good for postgres but with enhanced monitoring (i am unclear if it exists for anything other than postgres) you don’t need it specifically it is that good.

This is the best answer. Normal DBA investigation as to what is causing the underlying issue. It can be so many things. Are you doing a lot of converts? (varchar to nvarchar) Are you missing an index? Are you looping thru a Scan instead of a Seek? Is input data not being sanitized and causing an issue?

What size instance are you running and how many concurrent connections/queries are running when the CPU spikes?

If your instance size is only a couple vCPUs, but your app is making a large number of simultaneous queries, you might want to dial back your connection pool size on your app or increase your instance size to something with a higher vCPU count.

Or maybe look into optimizing the query being called.

https://smile.amazon.com/SQL-Tuning-Generating-Optimal-Execution/dp/0596005733/

I came across this with a company I helped. They were running t type instances but would constantly sit at above the base threshold. Even though they were configured to unlimited cpu credits it was still limiting it for reasons I won’t go into here. Moved to an m based instance and it was solved. Each problem is specific and would need to know more to give a better answer.

A couple of tips from past experience. Use APM and query monitor plugin to identify slow queries. Sometimes it’s a plugin that’s the root cause. Next explore hyperdb with aurora if your workload is read bound, or redis cache to minimize db hits. Also look at site optimizer plugins to aggregate your code.