Well I see a couple of things, first is you bought a base model 2017 iMac with a glacially slow 5400 RPM HD and that means it will never be fast. I also noted it has not been restarted in at least 4 days, please consider restarting it.
If I was in your shoes though I would SERIOUSLY consider replacing it with a new or Apple refurbished 24" iMac which will be dramatically faster as all iMacs sold now have SSDs which make them much much much faster than your current machine. The bottleneck on pre-2020 iMacs were they still used hard disks on most configurations. On the 21.5 models they used the slowest HD there was, 5400 RPM HD's. Also, a 2017 is considered a legacy machine as it will not run current versions of Mac OS and parts for it are largely unavailable. Another option is to upgrade to a current Mac mini and simply add your monitor.
However if you want to keep the 2017 then your best bet to make it faster and eliminate beach balling is to take the internal HD out of the equation. How you do that is by adding an external SSD, to learn how please click How to setup an external SSD as your startup disk. The SSD I would recommend is the following:
https://eshop.macsales.com/shop/owc-envoy-pro-sx
The downside of keeping the 2017 and investing money into it is you will still have an obsolete iMac.
Best of luck and if you have any questions please let us know.