bobbingwide / oik-bwtrace

debug trace for WordPress
https://www.oik-plugins.com/oik-plugins/oik-bwtrace-debug-trace-for-wordpress/
GNU General Public License v2.0
6 stars 1 forks source link

How to handle huge trace files #16

Closed bobbingwide closed 4 years ago

bobbingwide commented 8 years ago

Whilst it's not advisable to trace in a production system, it's possible to forget to disable tracing. If a trace file is not being reset for each request, ie. if the trace file is being appended to, then the file can get very large indeed.

Something needs to be done about this since it can lead to the server returning HTTP error code 500.

Note: There could be a problem with the trace file being written to even when tracing is only configured for a specific IP address. I'm looking into it.

bobbingwide commented 6 years ago

One possible solution to this is to implement some cycling logic using generations and sets of trace files. Where

The current logic for file naming is:

The new file mask would be of the form: path/filename.set.generation where

The generation logic will depend on the value given for limit.

limit Generation logic Generation
blank/null Not used. null
0 Unlimited .timestamp - from REQUEST_TIME_FLOAT
>0 Cycling .generation

The cycling logic is intended to ensure that concurrent requests do not use the same trace file.

Concurrently executed transactions may still choose the same file. If this happens a lot then use the limit =0 option. Trace file reset logic will apply to the selected trace file, except when the limit is 0.

reset generation Results in Supports concurrency
n n One big file . i.e. the current situation. Output mixed
n y Lots of ever increasing files Should do
y n Trace file reset every transaction Possible loss of data
y y Selected trace file reset Should do
bobbingwide commented 6 years ago

This change should also take in account and/or help address.

bobbingwide commented 6 years ago

The trace admin page should be updated to reflect the generation logic

  1. The trace file name will be wrong when the value of limit is set.
  2. The reset capability of the [bwtrace] shortcode needs to be revisited.
bobbingwide commented 6 years ago

Using the generation limit of 0 for REST calls allows concurrent tracing of the REST requests issued by the new block editor ( Gutenberg ). But it's not necessary for the standard browser, AJAX or batch ( CLI ) requests. So, I'm going to make 4 versions of the "limit" setting; one per request type. The Trace options page will be updated. screenshot-1.jpg reflects the latest version.

https://github.com/bobbingwide/oik-bwtrace/blob/23b773c69d108fee586cd05b6c6be9334e34a6fd/screenshot-1.jpg

Note: I haven't updated the PHPUnit tests yet.

bobbingwide commented 6 years ago

I noticed that trace reset is not working when the generation limit is not set.
The logic in trace_file-selector::reset_as_required() is incorrect. The solution is to change the switch statement to a simple if statement.

bobbingwide commented 4 years ago

There is still the possibility that the trace output files could use up a lot of disk space. The oik trace admin section for files shows the total space used for the files. And there’s logic to purge the files. This is documented, so I believe it’s safe to close the issue.