# Parallel Queries so Multiple CPUs utilized

**URL:** https://forum.djangoproject.com/t/parallel-queries-so-multiple-cpus-utilized/27194
**Category:** Using the ORM
**Created:** [January 19, 2024, 5:45pm UTC](https://forum.djangoproject.com/t/parallel-queries-so-multiple-cpus-utilized/27194 "2024-01-19T17:45:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![acknowledgeHim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/acknowledgehim/32/18549_2.png) [@acknowledgeHim](https://forum.djangoproject.com/u/acknowledgeHim)
#### Post date: [January 19, 2024, 5:45pm UTC](https://forum.djangoproject.com/t/parallel-queries-so-multiple-cpus-utilized/27194/1 "2024-01-19T17:45:10Z")

</div>

I have some report generation that will peg my CPU on the DB at 100% for several hours. However, it is only ever hitting 1 CPU when I have 32 available. How do I get the queries to optimally break out to utilize all of my CPU cores which would significantly reduce my querying time? I am running MySQL 8. Thanks!

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [January 19, 2024, 6:01pm UTC](https://forum.djangoproject.com/t/parallel-queries-so-multiple-cpus-utilized/27194/2 "2024-01-19T18:01:17Z")

</div>

That’s up to you to manage, depending upon exactly what you’re doing and how well they’re parallelizable and how you’re running the existing processes.

We’d need to see the specifics of what you’re doing to be able to offer specific recommendations.

---

<div class="post-metadata">

### Author: ![acknowledgeHim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/acknowledgehim/32/18549_2.png) [@acknowledgeHim](https://forum.djangoproject.com/u/acknowledgeHim)
#### Post date: [January 23, 2024, 10:57pm UTC](https://forum.djangoproject.com/t/parallel-queries-so-multiple-cpus-utilized/27194/3 "2024-01-23T22:57:12Z")

</div>

Thanks for the reply. Are there any good documents you can share about parallelizing my django code? (specifically queries)

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [January 23, 2024, 11:25pm UTC](https://forum.djangoproject.com/t/parallel-queries-so-multiple-cpus-utilized/27194/4 "2024-01-23T23:25:00Z")

</div>

There’s no generalized solution or approach - you can only address this in the context of your specific requirements.

I’m making the guess that if you’ve got a process issuing queries that runs for “several hours”, then you’re not doing this in the context of a single web request. In that case, the simplest approach is to break this larger set of queries into a number of smaller components or steps then use something like Celery to perform them.
