In an environment where there is thousands of pages, the PageNotFound action is extremely CPU intensive when the alternative page search hits many pages.
One such example to be considered is the space home page in an environment with thousands of spaces. If the home page of a space (EXAMPLE) is changed from "Home" to some other page and the URL mywiki/display/EXAMPLE/Home is visited, the alterative page search will hit every other "Home" page in all of the other spaces. From stack traces it appears that this operation will spend much time in the permission checking code path, triggering constant Hibernate session flushes to the DB.
Such operations may last tens of minutes in production environments and are often exacerbated when frustrated users constantly click refresh in an attempt to elicit a response from the application.
The options are to limit the number of alternatives we propose (useful in a general sense anyway, 2000 alternatives is not really helpful) and/or reduce the cost of permission checks in this case.
To apply the patch (tested in Confluence 2.6 and later):
1. Shut down Confluence
2. Find the file alternativepages.vm in the pages/ directory of your Confluence application. Replace it with the attached version.
3. Find the file xwork.xml in the WEB-INF/classes/ directory of your Confluence application. Find the following lines in the file:
Change the class in the first line to "com.atlassian.confluence.core.ConfluenceActionSupport" as shown below:
4. Start Confluence again. The "Page not found" page should now load quickly, irrespective of how many spaces are in the instance.