Heat dissipation can strongly affect the performance of your Raspberry Pi because it has built-in protection that reduces the processor clock rate to prevent hardware damage caused by overheating.

There are many passive and active cooling solutions to keep your CPU temperature down, but one stands out because it gives you direct control over the accessory and opens up many additional possibilities. It is called FanSHIM!
FanSHIM [https://learn.pimoroni.com/…fan-shim] – Official site with instructions for assembly, installation, configuration, and Python programming templates to control the device.
sudo apt install git python3-pip -y git clone https://github.com/pimoroni/fanshim-python cd fanshim-python
For Raspberry Pi OS, follow the steps below. If you are on Ubuntu 22.04, check the bonus section before proceeding.
sudo ./install.sh cd examples sudo ./install-service.sh --on-threshold 55 --off-threshold 40 --delay 1 --preempt --noled --nobutton sudo systemctl stop pimoroni-fanshim.service sudo systemctl disable pimoroni-fanshim.service sudo systemctl enable pimoroni-fanshim.service sudo systemctl start pimoroni-fanshim.service
It also has an RGB (Red Green Blue) LED that can be controlled through software using the Python libraries.

If your project will be running standalone as a print server, file server, web server, or similar, without regular handling or testing, it is recommended to solder the terminals.
The manufacturer claims soldering is not required, but I experienced poor contact at the terminals, which caused the fan to stay always on and the LED to stop working.
Soldering also keeps the board firmly positioned above the processor. I also experienced noise from the fan vibrating against the heatsink. Before soldering, place something underneath the fan to create a small gap between the parts.
Now it runs completely silently and only when needed!
BONUS
Dependencies for Ubuntu 22.04.
sudo apt install python3-rpi.gpio python3-metaconfig python3-dev libmysqlclient-dev python3-pip -y sudo pip3 install configparser