在netty中重用bytebuf(Reusing of bytebuf in netty)
我有Netty的http服务。 对于一组请求,http主体中只有“{}”的回复相同。 我有一个想法,以避免为每个这样的请求等创建新的缓冲区,所以我刚刚使用:
private static final ByteBuf EMPTY_REPLY = Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8);
在我的SimpleChannelInboundHandler中。 它只适用于我开始拥有的第一个查询
WARNING: Failed to mark a promise as success because it has failed already: DefaultChannelPromise@48c81b24(failure: io.netty.handler.codec.EncoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1), unnotified cause: io.netty.handler.codec.EncoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814) at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794) at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831) at travel.ServerHandler.writeResult(ServerHandler.java:475)
所以看起来缓冲区在第一次回复后会自动释放。 拥有这种缓冲区的正确方法是什么?
I have a http service with Netty. For a set of requests there is the same reply with just "{}" in http body. I had an idea to avoid creation of new buffer for each such request etc so I've just used:
private static final ByteBuf EMPTY_REPLY = Unpooled.copiedBuffer("{}", CharsetUtil.UTF_8);
in my SimpleChannelInboundHandler. It works only for first query, after it I start to have
WARNING: Failed to mark a promise as success because it has failed already: DefaultChannelPromise@48c81b24(failure: io.netty.handler.codec.EncoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1), unnotified cause: io.netty.handler.codec.EncoderException: io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:106) at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:738) at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:801) at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:814) at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:794) at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:831) at travel.ServerHandler.writeResult(ServerHandler.java:475)
so looks like buffer is automatically released after first reply. What is a correct way to have such buffer?
原文:https://stackoverflow.com/questions/45771169
最满意答案
只需使用反斜杠字符结束除last之外的所有行:
xmgrace \ dirA/argA \ dirB/argB \ dirC/argC
('<<'构造将附带的内容提供给命令的标准输入。)
Simply end all lines other than the last with a backslash character:
xmgrace \ dirA/argA \ dirB/argB \ dirC/argC
(The '<<' construct feeds the enclosed content to the standard input of the command.)
相关问答
更多-
如何通过命令行在shell脚本中传递参数(How to pass argument in expect through command line in shell script)[2022-08-30]
如果你想从参数中读取,你可以简单地通过 set username [lindex $argv 0]; set password [lindex $argv 1]; 并打印出来 send_user "$username $password" 该脚本将打印 $ ./test.exp user1 pass1 user1 pass1 您可以使用调试模式 $ ./test.exp -d user1 pass1 If you want to read from arguments, you can achiev ... -
只需使用反斜杠字符结束除last之外的所有行: xmgrace \ dirA/argA \ dirB/argB \ dirC/argC ('<<'构造将附带的内容提供给命令的标准输入。) Simply end all lines other than the last with a backslash character: xmgrace \ dirA/argA \ dirB/argB \ dirC/argC (The '<<' construct fee ...
-
这是一个黑客: for last; do true; done echo $last 这一个也很可移植(再次应该使用bash,ksh和sh),它不会移动参数,这可能是很好的。 它使用这样一个事实:如果你不告诉它要循环什么for隐含地循环参数,并且对于循环变量没有范围的事实:它们保留最后设置的值。 This is a bit of a hack: for last; do true; done echo $last This one is also pretty portable (again, shou ...
-
如何使shell脚本获取在命令行中传递的参数?(How to make a shell script take an argument passed in the command line?)[2022-07-01]
您确实应该使用$1 ,但是当您尝试运行脚本时,只需使用./your_script.sh your_argument不要在开头添加% 。 You should indeed use $1, but when you try to run your script just use ./your_script.sh your_argument don't add the % in the beginning. -
它的工作方式与您期望的一样,但fubar将成为第二个参数( $2 )而不是$1 。 所以如果你在你的/bin/command echo参数,你会得到如下的结果: echo "$1" # prints '-dosomething' echo "$2" # prints 'fubar' It works just the way you expect it to work, but fubar is going to be the second argument ( $2 ) and not $1. So i ...
-
将单个参数中的多个命令参数传递给shell函数(Passing multiple command arguments in single argument to shell function)[2024-03-17]
#!/bin/sh buildSomething() { eval "make ${1}" } buildSomething 'CFLAGS=\"-DX=1 -DY=1\" CXXFLAGS=\"-DXX=11 -DYY=11\"'" -j$(nproc)" #!/bin/sh buildSomething() { eval "make ${1}" } buildSomething 'CFLAGS=\"-DX=1 -DY=1\" CXXFLAGS=\"-DXX=11 -DYY=11 ... -
这是一种更简单的方法来重现您的问题: $ echo "-e" "foo" foo # What happened to "-e"? echo解析您的预期输出作为选项是POSIX在可移植脚本中警告此命令的原因之一。 如果您尝试转储参数以进行日志记录和调试,则可以使用bash的printf %q : #!/bin/bash # (does not work with sh) printf '%q ' "$0" "$@" printf '\n' 这将以这样的方式转义输出参 ...
-
在shell脚本中将MySQL名称作为参数传递给MySQL命令行(Pass as argument a table name in a MySQL command line, in a shell script)[2021-08-04]
-e的参数必须是单个字符串。 您将表名作为desc的单独参数,因此它被视为数据库名称参数。 将其更改为: -e "desc $1" 这是我的整个脚本: #!/bin/bash if [ "$1" != "" ]; then mysql \ -A -D bbodb_test \ -e "desc $1" \ -B -N \ | awk 'BEGIN {ORS="\t"};{print $1}' | awk '{print "#"$0} ... -
不同的是,当你执行"$ANT... $1" ,shell执行一个名为/path/to/ant release命令,注意,它是一个命令空格的命令。 所以找不到命令。 但是如果你"$ANT..." "$1"它将执行命令/paht/to/ant ,并将release作为参数/选项。 用这个测试,你会看到: kent$ "ls -l" zsh: command not found: ls -l #it thinks a command is "ls(space)-l" kent$ "ls" "-l" tota ...
-
尝试这个: eval $1 try this: eval $1