Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTEMIS-2984 Compressed large messages can leak native resources #3334

Closed
wants to merge 3 commits into from

Conversation

franz1981
Copy link
Contributor

import org.apache.activemq.artemis.api.core.ActiveMQException;

public interface LargeMessageController extends ActiveMQBuffer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an API change, isn't?

it's part of the Core Client API when dealing with large messages...

it's a client API.. I don't think. you can guarantee there are no users using this API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

answered on #3334 (comment)

@@ -104,42 +103,6 @@ public void testDeflaterReader2() throws Exception {
compareByteArray(allCompressed, output, compressedDataLength);
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened to this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InflaterReader was no longer needed, so could be removed (need to be sure of this one yet)!

@franz1981
Copy link
Contributor Author

franz1981 commented Nov 13, 2020

@clebertsuconic I'm reworking on this to save users to break their expectations but I see some interesting things that could improve large message streaming, see:

   private byte getByte(final long index) {
      checkForPacket(index);

      if (fileCache != null && index < packetPosition) {
         return fileCache.getByteFromCache(index);
      } else {
         return currentPacket.getChunk()[(int) (index - packetPosition)];
      }
   }

This method is the only one using FileCache to read data as part of the ActiveMQBuffer API on large messages, that's internal.
Large message streaming is slowed down (and get some additional memory footprint increase too) by the FileCache presence during message streaming, because it needs to save each incoming chunk into it as well, but if users won't read it's just useless work...

@franz1981 franz1981 force-pushed the no_mem_leaks branch 2 times, most recently from 480a877 to a8a3adc Compare November 13, 2020 07:39
@clebertsuconic
Copy link
Contributor

@franz1981 I'm lost on what you mean on your last comment.. you mean we should remove usage, or you have already reworked the usage?

@franz1981
Copy link
Contributor Author

franz1981 commented Nov 18, 2020

@clebertsuconic

you mean we should remove usage, or you have already reworked the usage?

I haven't done it because of the ActiveMQBuffer API on LargeMessageController we expose to users: if we drop it, we could save using FileCache while receiving chunks of the large message, both speeding it up and reducing its memory footprint.
Now we have a jmh module and I can work on a benchmark that can show the speedup I'm talking about

@clebertsuconic
Copy link
Contributor

@franz1981 what about the previous propose? to make the usage separate? we break the API but allow an alternative?

you had a class that you had moved to tests.. all I asked you was to move that class to the API.. so if someone is broken by this they could just change their code to use this new class.

they are using an internal method.. they would be broken by it.. but at least they would have an alternative.

if that's not possible then we can talk about breaking it for sure.

@michaelandrepearce
Copy link
Contributor

michaelandrepearce commented Nov 20, 2020

Do we really expose the controller to users? Yes its public but is it exposed in the client apis? I didnt think we do.

@clebertsuconic
Copy link
Contributor

�we don't expose it...

Franz had moved the controller to a separate class on a test..

all I asked was to have that class as part of the main jar.

But if that's a big deal.. just take it out then.

@franz1981
Copy link
Contributor Author

franz1981 commented Nov 21, 2020

@michaelandrepearce @clebertsuconic If we take the step to remove it I'm sure large message streaming can just drop any file cache and both code and perf will benefit there

what about the previous propose? to make the usage separate? we break the API but allow an alternative?

If the usage wasn't exposed to users, to remove the whole code paths that makes large msg streaming complex, saving both perf and leaky methods to exists as a whole. If removing isn't an option I can just prepare the code for a future removal, when we decide to do that, but we won't get any perf and stability benefits from removing it.
Adding a separate class to perform the read still won't allow me to remove the FileCache, so no perf benefits...

@michaelandrepearce
Copy link
Contributor

@franz1981 i think we established end users dont see this class we can do with it as we want. Removal, refactor, give it cups of tea.

@franz1981
Copy link
Contributor Author

Please don't merge it, I'm still trying to be 100% sure that file cache isn't used..but maybe it's used somehow...

@clebertsuconic
Copy link
Contributor

If it's easy. Keep the class available like before.

If not. Just take it out.

Keep it simple.

@franz1981
Copy link
Contributor Author

As it is now is just packed in a different class to make it more readeable :)
Hence this version on this PR should be fine, just need to run the CI on it

bytesRead += read;
}
while (bytesRead < chunkLimit);
assert bytesRead == chunkLimit;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this assert correct? what if you are reading a large message that Is not a multiple of chunkLimit?

@clebertsuconic
Copy link
Contributor

@franz1981 what's the status on this PR? is this ready to merge?

I saw briefly one assert (that I added a comment) that I wasn't sure at a first look.

@michaelandrepearce
Copy link
Contributor

@clebertsuconic / @franz1981 whats occuring with this, wanting to start clearing down old / stagnant PR's a bit of spring cleaning so to say - so we focus on stuff thats actively working on / relevant .

@franz1981
Copy link
Contributor Author

Closing this because large messages changed a bit recently: need to be reworked

@franz1981 franz1981 closed this Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants