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

Add Redis server example #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* License: Apache-2.0 License
* Required Java version: Java 11
* Maven coordinates:
** `io.netty.contrib:netty-codec-redis:5.0.0.Final-SNAPSHOT`
** `io.netty.contrib:netty-codec-redis:4.1.92.Final-SNAPSHOT`

6 changes: 3 additions & 3 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<parent>
<groupId>io.netty.contrib</groupId>
<artifactId>netty-codec-redis-parent</artifactId>
<version>5.0.0.Final-SNAPSHOT</version>
<version>4.1.92.Final-SNAPSHOT</version>
</parent>

<artifactId>netty-codec-redis-benchmarks</artifactId>
<version>${parent.version}</version>

<properties>
<jmh.version>1.33</jmh.version>
<jmh.version>1.36</jmh.version>
</properties>

<build>
Expand Down Expand Up @@ -44,4 +44,4 @@
<version>${jmh.version}</version>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
Expand All @@ -15,17 +15,9 @@
*/
package io.netty.contrib.microbenchmarks.redis;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import io.netty.contrib.handler.codec.redis.ArrayRedisMessage;
import io.netty.contrib.handler.codec.redis.FullBulkStringRedisMessage;
import io.netty.contrib.handler.codec.redis.RedisEncoder;
import io.netty.contrib.handler.codec.redis.RedisMessage;
import io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext;
import io.netty.util.concurrent.Future;
import java.util.ArrayList;
import java.util.List;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
Expand All @@ -38,15 +30,25 @@
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;

import java.util.ArrayList;
import java.util.List;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.contrib.handler.codec.redis.ArrayRedisMessage;
import io.netty.contrib.handler.codec.redis.FullBulkStringRedisMessage;
import io.netty.contrib.handler.codec.redis.RedisEncoder;
import io.netty.contrib.handler.codec.redis.RedisMessage;
import io.netty.microbench.channel.EmbeddedChannelWriteReleaseHandlerContext;
import io.netty.microbench.util.AbstractMicrobenchmark;

@State(Scope.Benchmark)
@Fork(1)
@Threads(1)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
public class RedisEncoderBenchmark {
public class RedisEncoderBenchmark extends AbstractMicrobenchmark {
private RedisEncoder encoder;
private ByteBuf content;
private ChannelHandlerContext context;
Expand All @@ -55,6 +57,9 @@ public class RedisEncoderBenchmark {
@Param({ "true", "false" })
public boolean pooledAllocator;

@Param({ "true", "false" })
public boolean voidPromise;

@Param({ "50", "200", "1000" })
public int arraySize;

Expand All @@ -65,7 +70,7 @@ public void setup() {
content.writeBytes(bytes);
ByteBuf testContent = Unpooled.unreleasableBuffer(content.asReadOnly());

List<RedisMessage> rList = new ArrayList<>(arraySize);
List<RedisMessage> rList = new ArrayList<RedisMessage>(arraySize);
for (int i = 0; i < arraySize; ++i) {
rList.add(new FullBulkStringRedisMessage(testContent));
}
Expand All @@ -75,20 +80,23 @@ public void setup() {
UnpooledByteBufAllocator.DEFAULT, encoder) {
@Override
protected void handleException(Throwable t) {
throw new AssertionError("Unexpected exception", t);
handleUnexpectedException(t);
}
};
}

@TearDown(Level.Trial)
public void tearDown() {
redisArray.release();
public void teardown() {
content.release();
content = null;
}

@Benchmark
public Future<Void> writeArray() {
return encoder.write(context, redisArray.retain());
public void writeArray() throws Exception {
encoder.write(context, redisArray.retain(), newPromise());
}

private ChannelPromise newPromise() {
return voidPromise ? context.voidPromise() : context.newPromise();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
Expand All @@ -14,6 +14,6 @@
* under the License.
*/
/**
* Benchmarks for {@link io.netty.contrib.handler.codec.redis}.
* Benchmarks for {@link io.netty.handler.codec.redis}.
*/
package io.netty.contrib.microbenchmarks.redis;
6 changes: 3 additions & 3 deletions codec-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<parent>
<groupId>io.netty.contrib</groupId>
<artifactId>netty-codec-redis-parent</artifactId>
<version>5.0.0.Final-SNAPSHOT</version>
<version>4.1.92.Final-SNAPSHOT</version>
</parent>

<artifactId>codec-redis</artifactId>
<artifactId>netty-codec-redis</artifactId>
<version>${parent.version}</version>
<name>Netty/Codec/Redis</name>
<packaging>jar</packaging>
Expand Down Expand Up @@ -52,4 +52,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,10 +12,10 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.netty.contrib.handler.codec.redis;

import static java.util.Objects.requireNonNull;
package io.netty.contrib.handler.codec.redis;

import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;

Expand All @@ -28,7 +28,7 @@ public abstract class AbstractStringRedisMessage implements RedisMessage {
private final String content;

AbstractStringRedisMessage(String content) {
this.content = requireNonNull(content, "content");
this.content = ObjectUtil.checkNotNull(content, "content");
}

/**
Expand All @@ -48,4 +48,5 @@ public String toString() {
.append(content)
.append(']').toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import io.netty.util.internal.StringUtil;
Expand All @@ -30,7 +31,7 @@ public class ArrayHeaderRedisMessage implements RedisMessage {
*/
public ArrayHeaderRedisMessage(long length) {
if (length < RedisConstants.NULL_VALUE) {
throw new RedisCodecException("length: " + length + " (expected: >= " + RedisConstants.NULL_VALUE + ')');
throw new RedisCodecException("length: " + length + " (expected: >= " + RedisConstants.NULL_VALUE + ")");
}
this.length = length;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,18 +12,18 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import static java.util.Objects.requireNonNull;
import java.util.Collections;
import java.util.List;

import io.netty.util.AbstractReferenceCounted;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.StringUtil;
import io.netty.util.internal.UnstableApi;

import java.util.Collections;
import java.util.List;

/**
* Arrays of <a href="https://redis.io/topics/protocol">RESP</a>.
*/
Expand All @@ -43,7 +43,7 @@ private ArrayRedisMessage() {
*/
public ArrayRedisMessage(List<RedisMessage> children) {
// do not retain here. children are already retained when created.
this.children = requireNonNull(children, "children");
this.children = ObjectUtil.checkNotNull(children, "children");
}

/**
Expand Down Expand Up @@ -173,4 +173,5 @@ public String toString() {
return "EmptyArrayRedisMessage";
}
};

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import io.netty.util.internal.UnstableApi;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import io.netty.buffer.ByteBuf;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import io.netty.buffer.ByteBuf;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import io.netty.buffer.ByteBuf;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Netty Project
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
Expand All @@ -12,6 +12,7 @@
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package io.netty.contrib.handler.codec.redis;

import io.netty.util.internal.UnstableApi;
Expand All @@ -30,4 +31,5 @@ public final class ErrorRedisMessage extends AbstractStringRedisMessage {
public ErrorRedisMessage(String content) {
super(content);
}

}
Loading