Generating a GetCapabilities file for a WMS service with a lot of layers will cause the CPU of the server to increase and possibly become unresponsive for a long time.
The workaround is to generate a static GetCapabilities file for users to download instead of dynamically creating a capabilities file for each request.