4 ms·
I've worked in applications where a lot of IO is required. If performance is something your application cares about then you'll probably end up using direct Byt
by syntacticbs 3y ago
I've worked in applications where a lot of IO is required. If performance is something your application cares about then you'll probably end up using direct ByteBuffers which are off heap and you'll likely want to set a sensible value for: -XX:MaxDirectMemorySize
However if this value ever does get exceeded, you need some way of tracking down what allocations happened prior to your OutOfMemory exception.
Though the above article implies the sampling rate is once a second (I guess there's some cost to increasing that rate). Usually you won't be allocating direct memory on the reg since it's expensive to allocate and deallocate relative to heap memory so you kind of want to capture ALL allocations and deallocations. As such a sample based approach is not ideal due to possibly missing some data between samples.
- MrBuddyCasino 3y ago> If performance is something your application cares about then you'll probably end up using direct ByteBuffers What made you decide to go this route, instead of pre-allocating a pool of buffers (possibly thread-local) and recycling them?
- syntacticbs 3y agoPre-allocating up front would also have been valid way of doing things. For the specific use cases I have worked on though, I'm not sure it would have had any additional performance benefits. The specific class of systems I've worked on usually have only a few sockets which open at the start of a day and stay connected until the end of a day. Pre-allocating would make the socket opening process faster but that is not usually the part of an application life cycle that needs optimising. If there were lots of sockets opening and closing or the speed of opening and closing needed optimisation, then what you suggested would be a good idea.
- marginalia_nu 3y ago> I've worked in applications where a lot of IO is required. If performance is something your application cares about then you'll probably end up using direct ByteBuffers which are off heap and you'll likely want to set a sensible value for: -XX:MaxDirectMemorySize It's also worth noting that if your Xmx is larger than 32 GB, you can't use CompressedOOPs, which is a bad deal. Off-heap memory lets you skirt that limitation while still allocating >32GB.
- vanillax 3y agothanks this is helpful!