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

Netty version update 3.9 -> 4.1 #29

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

esevastyanov
Copy link

Netty was improved a lot from 3.9 to 4.1
3.x -> 4.0 http://netty.io/wiki/new-and-noteworthy-in-4.0.html
4.0 -> 4.1 http://netty.io/wiki/new-and-noteworthy-in-4.1.html

  • Reduced GC pressure
  • Reduced memory bandwidth consumption
  • New codecs and handlers

@drcrallen
Copy link
Contributor

Should do a major version update

@drcrallen
Copy link
Contributor

On a side note, I'm excited to try this out: https://github.com/netty/netty/tree/4.1/codec-http2

@logarithm
Copy link
Contributor

Our last tries showed that netty 4.1 is incompatible with spark 2.1.0. Could you please make sure, that this http-client implementation will work correctly with netty 4.0.x and 4.1.x in run time.

@drcrallen
Copy link
Contributor

@logarithm do we have a record of what the problem was?

@logarithm
Copy link
Contributor

@drcrallen Which record do you mean? We have commit in our private repo which fixes it. Problem was that spark is using 4.0.29 netty version, but in runtime we had 4.1. and spark was failing with exception.

@drcrallen
Copy link
Contributor

drcrallen commented Jun 5, 2017

pom.xml Outdated
<artifactId>netty</artifactId>
<version>3.10.6.Final</version>
<artifactId>netty-all</artifactId>
<version>4.1.8.Final</version>
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why not 4.1.11?

Copy link
Contributor

Choose a reason for hiding this comment

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

4.1.12

Copy link
Author

Choose a reason for hiding this comment

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

Its release cycle is impressive

Copy link

Choose a reason for hiding this comment

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

4.1.13 😃

@@ -56,7 +56,7 @@ public String getEncodingString()
*
* @return encoding name
*/
public abstract String getEncodingString();
public abstract String getEncodingString(); /*TODO use for Content-Encoding*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Please file a Github/Jira issue about that

if (!headers.containsKey(HttpHeaders.Names.HOST)) {
httpRequest.headers().add(HttpHeaders.Names.HOST, getHost(url));
String uri = urlFile.isEmpty() ? "/" : urlFile;
final DefaultFullHttpRequest httpRequest =
Copy link
Contributor

Choose a reason for hiding this comment

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

suggested if-else instead of ternary


if (httpChunk.isLast()) {
response = handler.handleChunk(response, httpChunk);
if (response.isFinished() && !retVal.isDone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change? Before this block was executed only if the chunk is not last

Copy link
Author

Choose a reason for hiding this comment

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

Even last chunk has content now thus it should be handled

if (response.isFinished() && !retVal.isDone()) {
retVal.set((Final) response.getObj());
}
ctx.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why added closing context?

AppendableByteArrayInputStream in = new AppendableByteArrayInputStream();
in.add(getContentBytes(response.getContent()));
in.add(content.array());
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a guarantee that the array exists? ByteBuf has hasArray() method. Also arrayOffset() should be considered.

Copy link
Author

Choose a reason for hiding this comment

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

good catch

)
{
clientResponse.getObj().add(getContentBytes(chunk.getContent()));
clientResponse.getObj().add(chunk.content().array());
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

final ChannelBuffer channelBuffer = chunk.getContent();
final int bytes = channelBuffer.readableBytes();
if (bytes > 0) {
if (chunk.content().hasArray()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hasArray() means not that there are no bytes, it means that the ByteBuf is backed by off-heap memory.

@@ -112,7 +111,7 @@ public InputStream nextElement()
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
}
byteCount.addAndGet(bytes);
byteCount.addAndGet(chunk.content().array().length);
Copy link
Contributor

Choose a reason for hiding this comment

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

readableBytes()?

@@ -35,21 +36,22 @@ public ToStringResponseHandler(Charset charset)
@Override
public ClientResponse<StringBuilder> handleResponse(HttpResponse response)
{
return ClientResponse.unfinished(new StringBuilder(response.getContent().toString(charset)));
ByteBuf content = response instanceof HttpContent ? ((HttpContent) response).content() : Unpooled.EMPTY_BUFFER;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested if-else and provide "" empty string directly instead of converting empty buffer to empty string

Copy link
Contributor

@logarithm logarithm left a comment

Choose a reason for hiding this comment

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

Request changes just in order to not forget to test this PR with netty 4.0.42.Final in runtime to make sure it will work with spark 2.1

@drcrallen
Copy link
Contributor

@logarithm / @esevastyanov is it possible to organize the POM such that the default profile uses 4.1.x, and we have the ability to specify a profile for 4.0.x so we can test?

@drcrallen
Copy link
Contributor

Or we can just raise the issue with spark again and get the upstream on 4.1

@logarithm
Copy link
Contributor

To rise issue with spark looks like the best solution, but it might take time.

@@ -123,7 +124,7 @@ public void run()
// Read headers
String header;
while (!(header = in.readLine()).equals("")) {
if (header.equals("Accept-Encoding: identity")) {
if (header.toLowerCase().equals("Accept-Encoding: identity".toLowerCase())) {
Copy link

Choose a reason for hiding this comment

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

String.equalsIgnoreCase()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants