Optimal thread count for runner jobs

How can I determine the optimal concurrency for a CPU-bound job on a GitLab CI runner? Alternatively, how can I determine the (maximum) count of parallel jobs on the same machine?

For example, my employer’s runner has 16 cores. When my task is the only job, it would be optimal to run it with a concurrency of about 16. But when I’m just one of 32 parallel jobs, running with a high concurrency can result in no individual thread making much useful progress, and ugly timeouts when I’m communicating with external services because the threads talking with the services rarely get to run.