BookStackApp / BookStack

A platform to create documentation/wiki content built with PHP & Laravel
https://www.bookstackapp.com/
MIT License
15.02k stars 1.88k forks source link

Saving a moderately big page performance problem #5080

Open CamaroSS opened 3 months ago

CamaroSS commented 3 months ago

Describe the Bug

Creating a moderately big page can hog up all of the server's CPU resources. The document saving process itself hangs somewhere in /BookStack/app/Util/HtmlDocument.php As the page is hung up saving, there are background PUT requests that make it worse because they hang as well.

The issue might be mitigated by not allowing more than one draft saving request on page at a time. Stopping draft saving requests after clicking "Save page" might help as well.

Steps to Reproduce

  1. Create a new page
  2. Go to source code editor
  3. Copy the attached file contents there. It's ~4Mb worth of HTML with lots of tables which is a database structure scheme1 - Copy.zip
  4. Try to save the page

Expected Behaviour

The page is saved after a while

Screenshots or Additional Context

Instead I get PHP Fatal error: Maximum execution time of 1200 seconds exceeded in {path}\BookStack\app\Util\HtmlDocument.php on line 62 for the main saving process and the background draft saving processes. The CPU gets loaded up to 100%.

Browser Details

Firefox 127 on Windows 11

Exact BookStack Version

v24.05.1

ssddanbrown commented 3 months ago

4MB is really quite large. There's over 68k table cells in that document. At some point content will come across limits, and that may very depending on specific content and system resources. We can look into where bottlenecks may be for this kind of content, and look to improve that where possible/reasonable, but ultimately this is a large amount of content that may be better suited to be split up.

CamaroSS commented 3 months ago

I understand. But please mind that if one saving process is busy, it's better not to launch new ones. What I saw was one working POST and multiple PUT requests in Network tab.