Repository navigation
Conversation
|
@siyengar thanks for this PR! Could you please also sign our cla and adjust the commit message to match our template? http://netty.io/s/icla Please let me know once done |
|
@siyengar also do you use netty-tcnative as a standalone thing or with netty ? |
| // Make a BIO pair (network and internal) for the provided SSL * and return the network BIO | ||
| // Make a BIO pair (network and internal) for the provided SSL * with the default BIO size | ||
| // and return the network BIO | ||
| TCN_IMPLEMENT_CALL(jlong, SSL, makeNetworkBIO)(TCN_STDARGS, |
There was a problem hiding this comment.
just remove this method and always call makeNetworkBIO0
| return P2J(network_bio); | ||
| // Make a BIO pair (network and internal) for the provided SSL * with a max size and max size | ||
| // of max_bio_size and return the network BIO | ||
| TCN_IMPLEMENT_CALL(jlong, SSL, makeNetworkBIOWithSize)(TCN_STDARGS, |
| * @param maxBioSize The maximum size of the BIO. | ||
| * @return pointer to the Network BIO (BIO *) | ||
| */ | ||
| public static native long makeNetworkBIOWithSize(long ssl, int maxBioSize); |
| * | ||
| * @see #makeNetworkBIOWithSize(long, int) | ||
| */ | ||
| public static native long makeNetworkBIO(long ssl); |
There was a problem hiding this comment.
@siyengar can you just rename this method to makeNetworkBIO0 and have it take maxBioSize . Then add static public methods to preserve old API:
Something like this:
public static long makeNetworkBIO(long ssl) {
return makeNetworkBIO0(ssl, maxBioSize);
}
public static long makeNetworkBIO(long ssl, int maxBioSize) {
return makeNetworkBIO0(ssl, maxBioSize);
}
private static native long makeNetworkBIO0(long ssl, int maxBioSize);This way we can keep the changes / c code minimal. WDYT ?
There was a problem hiding this comment.
This works great, will make this change
| } | ||
|
|
||
| // max_bio_size = 0 is the default BIO size. | ||
| static jlong createNetworkBIO(JNIEnv *e, jlong ssl, jint max_bio_size) { |
There was a problem hiding this comment.
see below (SSL.java) for comments :)
|
@normanmaurer we do use netty-tcnative with netty, however we're still on an older version of netty so in some places we use netty-tcnative directly. The project is https://github.com/facebook/nifty which is thrift over netty. will update the CLA and message |
|
@siyengar I see... can you share what buffer size you usually use and if you are aware of a minimum that is required ? |
|
@normanmaurer I'm still experimenting with the buffer size. After I found this problem, I first tried a buffer of 1K for read and write, and that reduced memory usage significantly, by > 3gigs since we have a large number connections on this service (and not a lot of free memory) in certain cases, however it increased CPU utilization by about 10% presumably because more ssl record encryption calls + syscalls calls need to be made for 1 application write. So we're still tuning this buffer w.r.t how much we can tolerate. Openssl and boringssl have no minimum size restriction on this buffer from reading their source. |
|
@siyengar ok cool... let me know once you find the "sweet spot". About how many connections we are talking here on the box ? Also say hi to @bmatheny and @andrewcox ;) |
|
Ah ya, there are > 60K connections on average, which can spike sometimes, with a headroom of about 4Gigs. Openssl and boringssl do ephemeral allocations per write as well of 16K for read and write buffers (write_fragment_size), however after this change it doesn't seem to bite us much. Will definitely say hi :), we're all enjoying using "netty" with wangle very much as well. |
|
made the requested changes. Thanks for the reviews @normanmaurer |
|
Careful @normanmaurer, I stalk the netty PR's ;) Come visit next time you're here! |
|
@bmatheny lol... I will for sure... March it is ;) |
|
looks like CI failed during cmake of boringssl stable which this diff shouldn't affect. Also it passes for me locally just fine, but then again I'm building on a mac |
|
@siyengar I installed a new ci server today and it seems like I missed to install |
|
Thanks @normanmaurer, would love a release with this change if everything passes. I can then update open-source nifty to use this API rather than relying on internal changes. |
|
@siyengar thats the plan at the end ... |
| * @return pointer to the Network BIO (BIO *) | ||
| */ | ||
| public static native long makeNetworkBIO(long ssl); | ||
| public static native long makeNetworkBIO0(long ssl, int maxBioSize); |
|
updated with changes. |
| */ | ||
| public static native void freeSSL(long ssl); | ||
|
|
||
|
|
There was a problem hiding this comment.
@siyengar just one last thing before I merge ... Can you remove this empty line as there is already one . Thanks!
| // Make a BIO pair (network and internal) for the provided SSL * and return the network BIO | ||
| TCN_IMPLEMENT_CALL(jlong, SSL, makeNetworkBIO)(TCN_STDARGS, | ||
| jlong ssl /* SSL * */) { | ||
| // Make a BIO pair (network and internal) for the provided SSL * with a max size and max size |
There was a problem hiding this comment.
Also this reads a bit strange: with a max size and max size. Can you rework this comment.
|
addressed comments. |
75b6675 to
9ec1ef4
Compare
| } | ||
|
|
||
| if (BIO_new_bio_pair(&internal_bio, 0, &network_bio, 0) != 1) { | ||
| if (BIO_new_bio_pair(&internal_bio, max_bio_size, &network_bio, max_bio_size) != 1) { |
There was a problem hiding this comment.
There is an implicit cast of signed -> unsigned here which may cause warnings, which may be treated as errors depending on environment, on some compilers. Can you be explicit about the type conversion?
There was a problem hiding this comment.
great catch. will do an explicit conversion here.
Motivation: We observed that when the number of connections is very large on a service, the machines started running out of memory. On memory analysis the major consumer of memory was found to be the bio allocation. Modifications: The default max bio size is 17K. This allows the parameter to be tunable. Result: We've found this extremely useful for scaling large services. On reducing the buffer size memory usage can be reduced signficantly. The CPU usage goes up a bit when this is reduced so everyone find their own sweet spot.
|
I didn't add another check that size_t size > jint size and making that assumption of the arch here. Does netty-tcnative run on any archs where that is not true? |
|
That should be fine |
|
@Scottmitch satisfied as well? |
Scottmitch
left a comment
There was a problem hiding this comment.
lgtm ... thanks @siyengar !
|
@normanmaurer do you have an estimate on when Fork24 will be released? |
|
@siyengar tomorrow 👍 |
|
we finally ended up using a 2k buffer which seems to work fine. We're now toying with the idea of deallocating and allocating the buffer after each write. |
Add max bio size param
Motivation:
We observed that when the number of connections is very large
on a service, the machines started running out of memory.
On memory analysis the major consumer of memory was found
to be the bio allocation.
Modifications:
The default max bio size is 17K. This allows the parameter to be
tunable.
Result:
We've found this extremely useful for scaling large services. On
reducing the buffer size memory usage can be reduced signficantly. The
CPU usage goes up a bit when this is reduced so everyone find their
own sweet spot.