otros-systems / otroslogviewer

Log viewer focused on developers work
Apache License 2.0
424 stars 87 forks source link

Parse clipboard - java.lang.OutOfMemoryError: Java heap space #620

Closed DavidAccola closed 2 years ago

DavidAccola commented 2 years ago

How large of a clipboard copy/paste can OtrosLogViewer reasonably be expected to handle?

parse clipboard

java.lang.OutOfMemoryError: Java heap space

This is pasting what amounts to a 84 mb log file.

benlazaro commented 2 years ago

@DavidAccola For now this is tide to the memory allocated for the application. You can change that in the olv batch/shell file. There is an option for setting the max memory allocated to the java process which looks like this:

set MEMORY=-Xmx4096m

The default value is -Xmx1024m and with that value I was able to reproduce your problem. Once I changed that to the value in the example above, I was able to paste the full log. I don't think there is anything documented regarding on how much data we should be able to handle in the "Paste clipboard" functionality, but I have 2 possible solutions:

  1. We could change the implementation to read the clipboard data in chunks and save it into a temporary file in disk, then we treat it as any other file. The tmp file would need to be deleted on exit. That way can support larger amounts of data pasted from the clipboard without having to modify the memory allocated for the java process.
  2. See solution number 1 (I thought I had another one, really)

The pro is that we can handle it the same way than any other log file, though I tried loading the 80Mb file that I created into OLV and it also slapped me with an OutOfMemoryError, which means that we are loading the whole file into memory when we are parsing it, and that also need to be improved.

So at a minimum I see 1 bug:

If we do decide to change the implementation so that we can handle the message in a more performant way, the fix above would not apply anymore since we would not be running out of memory, but there would be other changes in the application that we would need to make:

  1. Read the clipboard data in chunks and save it to a tmp log file. (delete file on exit)
  2. Read the log file data in chunks as well so that it doesn't require reconfiguring the memory configuration (this may affect other functionality such as search in the log, etc... so we would need to look into that to see if this solution is viable)
benlazaro commented 2 years ago

We can also break this into 2 fixes

  1. Fix the issue so that the application fails gracefully
  2. Create another issue to enhance this functionality, which would be deferred for a bigger milestone.

thoughts anyone?

svennissel commented 2 years ago

It is really a bad implementation of Java Clipboard. I catch the OutOfMemory and display a error message with the hint to change the memory settings. I think this will be work in most cases because the Clipbord Method will after leave release the memory.

memory limit reached

benlazaro commented 2 years ago

Just a quick note, the word "to" is repeated in the error message, in case you haven't caught it yet. It should be "too big to parse".