forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yury-Fridlyand <[email protected]>
- Loading branch information
1 parent
d6b72ac
commit 58f7b58
Showing
9 changed files
with
270 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/ChannelHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package javababushka.benchmarks.clients.babushka; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.channel.ChannelPromise; | ||
import io.netty.channel.CombinedChannelDuplexHandler; | ||
|
||
public class ChannelHandler extends CombinedChannelDuplexHandler { | ||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { | ||
super.channelRead(ctx, msg); | ||
} | ||
|
||
@Override | ||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { | ||
super.write(ctx, msg, promise); | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniNettyClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package javababushka.benchmarks.clients.babushka; | ||
|
||
import static connection_request.ConnectionRequestOuterClass.ConnectionRequest; | ||
import static connection_request.ConnectionRequestOuterClass.AddressInfo; | ||
import static connection_request.ConnectionRequestOuterClass.ReadFromReplicaStrategy; | ||
import static connection_request.ConnectionRequestOuterClass.ConnectionRetryStrategy; | ||
import static connection_request.ConnectionRequestOuterClass.AuthenticationInfo; | ||
import static connection_request.ConnectionRequestOuterClass.TlsMode; | ||
|
||
import io.netty.bootstrap.Bootstrap; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandler; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.channel.ChannelInitializer; | ||
import io.netty.channel.ChannelOutboundHandler; | ||
import io.netty.channel.ChannelOutboundHandlerAdapter; | ||
import io.netty.channel.CombinedChannelDuplexHandler; | ||
import io.netty.channel.EventLoopGroup; | ||
import io.netty.channel.SimpleChannelInboundHandler; | ||
import io.netty.channel.SimpleUserEventChannelHandler; | ||
import io.netty.channel.epoll.EpollDomainSocketChannel; | ||
import io.netty.channel.epoll.EpollEventLoopGroup; | ||
import io.netty.channel.unix.UnixChannel; | ||
import javababushka.benchmarks.clients.SyncClient; | ||
import javababushka.benchmarks.utils.ConnectionSettings; | ||
import io.netty.channel.nio.NioEventLoopGroup; | ||
import io.netty.channel.socket.SocketChannel; | ||
import io.netty.channel.socket.nio.NioSocketChannel; | ||
import io.netty.channel.unix.DomainSocketAddress; | ||
import javababushka.client.RedisClient; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class JniNettyClient implements SyncClient { | ||
|
||
private final static String unixSocket = getSocket(); | ||
|
||
private Channel channel = null; | ||
|
||
// TODO static or move to constructor? | ||
private static String getSocket() { | ||
try { | ||
return RedisClient.startSocketListenerExternal(); | ||
} catch (Exception | UnsatisfiedLinkError e) { | ||
System.err.printf("Failed to get UDS from babushka and dedushka: %s%n%n", e); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void connectToRedis() { | ||
connectToRedis(new ConnectionSettings("localhost", 6379, false)); | ||
} | ||
|
||
@Override | ||
public void connectToRedis(ConnectionSettings connectionSettings) { | ||
|
||
// TODO maybe move to constructor or to static? | ||
// ====== | ||
Bootstrap bootstrap = new Bootstrap(); | ||
EventLoopGroup group = new EpollEventLoopGroup(); | ||
//EventLoopGroup group = new NioEventLoopGroup(); | ||
try { | ||
bootstrap | ||
.group(group) | ||
.channel(EpollDomainSocketChannel.class) | ||
.handler(new ChannelInitializer<UnixChannel>() { | ||
@Override | ||
public void initChannel(UnixChannel ch) throws Exception { | ||
ch | ||
.pipeline() | ||
// TODO encoder/decoder | ||
.addLast(new ChannelInboundHandlerAdapter()) | ||
.addLast(new ChannelOutboundHandlerAdapter()); | ||
/* | ||
.addLast(new SimpleUserEventChannelHandler<String>() { | ||
@Override | ||
protected void eventReceived(ChannelHandlerContext ctx, String evt) throws Exception { | ||
} | ||
}); | ||
*/ | ||
//.addLast(new CombinedChannelDuplexHandler(new ChannelInboundHandler(), new ChannelOutboundHandler())); | ||
} | ||
}); | ||
channel = bootstrap.connect(new DomainSocketAddress(unixSocket)).sync().channel(); | ||
|
||
|
||
//channel.writeAndFlush(request); | ||
|
||
//channel.closeFuture().sync(); | ||
} | ||
catch (Exception e) { | ||
int a = 5; | ||
} finally { | ||
//epollEventLoopGroup.shutdownGracefully(); | ||
} | ||
// ====== | ||
|
||
var request = ConnectionRequest.newBuilder() | ||
.addAddresses( | ||
AddressInfo.newBuilder() | ||
.setHost(connectionSettings.host) | ||
.setPort(connectionSettings.port)) | ||
.setTlsMode(connectionSettings.useSsl // TODO: secure or insecure TLS? | ||
? TlsMode.SecureTls | ||
: TlsMode.NoTls) | ||
.setClusterModeEnabled(false) | ||
// In millis | ||
.setResponseTimeout(250) | ||
// In millis | ||
.setClientCreationTimeout(2500) | ||
.setReadFromReplicaStrategy(ReadFromReplicaStrategy.AlwaysFromPrimary) | ||
.setConnectionRetryStrategy( | ||
ConnectionRetryStrategy.newBuilder() | ||
.setNumberOfRetries(1) | ||
.setFactor(1) | ||
.setExponentBase(1)) | ||
.setAuthenticationInfo( | ||
AuthenticationInfo.newBuilder() | ||
.setPassword("") | ||
.setUsername("default")) | ||
.setDatabaseId(0) | ||
.build(); | ||
|
||
channel.writeAndFlush(request.toByteArray()); | ||
channel.read(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "JNI Netty"; | ||
} | ||
|
||
@Override | ||
public void set(String key, String value) { | ||
|
||
} | ||
|
||
@Override | ||
public String get(String key) { | ||
return null; | ||
} | ||
|
||
public static void main(String[] args) { | ||
var client = new JniNettyClient(); | ||
client.connectToRedis(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters