Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
pulsar
提交
3e4e1276
pulsar
项目概览
apache
/
pulsar
通知
129
Star
40
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
pulsar
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
体验新版 GitCode,发现更多精彩内容 >>
提交
3e4e1276
编写于
10月 17, 2016
作者:
R
Rajan
提交者:
Matteo Merli
10月 17, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce Dispatcher-totalPermits by number of messages delivered in batch (#67)
上级
bd49d699
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
16 deletion
+25
-16
pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/Consumer.java
...c/main/java/com/yahoo/pulsar/broker/service/Consumer.java
+11
-5
pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
...ice/persistent/PersistentDispatcherMultipleConsumers.java
+13
-10
pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/persistent/PersistentDispatcherSingleActiveConsumer.java
.../persistent/PersistentDispatcherSingleActiveConsumer.java
+1
-1
未找到文件。
pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/Consumer.java
浏览文件 @
3e4e1276
...
...
@@ -27,6 +27,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import
org.apache.bookkeeper.mledger.Entry
;
import
org.apache.bookkeeper.mledger.impl.PositionImpl
;
import
org.apache.bookkeeper.mledger.util.Rate
;
import
org.apache.commons.lang3.tuple.MutablePair
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -115,19 +117,22 @@ public class Consumer {
*
* @return a promise that can be use to track when all the data has been written into the socket
*/
public
ChannelPromise
sendMessages
(
final
List
<
Entry
>
entries
)
{
public
Pair
<
ChannelPromise
,
Integer
>
sendMessages
(
final
List
<
Entry
>
entries
)
{
final
ChannelHandlerContext
ctx
=
cnx
.
ctx
();
final
MutablePair
<
ChannelPromise
,
Integer
>
sentMessages
=
new
MutablePair
<
ChannelPromise
,
Integer
>();
final
ChannelPromise
writePromise
=
ctx
.
newPromise
();
sentMessages
.
setLeft
(
writePromise
);
if
(
entries
.
isEmpty
())
{
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"[{}] List of messages is empty, triggering write future immediately for consumerId {}"
,
subscription
,
consumerId
);
}
writePromise
.
setSuccess
();
return
writePromise
;
sentMessages
.
setRight
(
0
);
return
sentMessages
;
}
updatePermitsAndPendingAcks
(
entries
);
sentMessages
.
setRight
(
updatePermitsAndPendingAcks
(
entries
)
);
ctx
.
channel
().
eventLoop
().
execute
(()
->
{
for
(
int
i
=
0
;
i
<
entries
.
size
();
i
++)
{
...
...
@@ -165,7 +170,7 @@ public class Consumer {
ctx
.
flush
();
});
return
writePromise
;
return
sentMessages
;
}
private
void
incrementUnackedMessages
(
int
ackedMessages
)
{
...
...
@@ -192,7 +197,7 @@ public class Consumer {
return
-
1
;
}
void
updatePermitsAndPendingAcks
(
final
List
<
Entry
>
entries
)
{
int
updatePermitsAndPendingAcks
(
final
List
<
Entry
>
entries
)
{
int
permitsToReduce
=
0
;
Iterator
<
Entry
>
iter
=
entries
.
iterator
();
while
(
iter
.
hasNext
())
{
...
...
@@ -221,6 +226,7 @@ public class Consumer {
log
.
debug
(
"[{}] [{}] message permits dropped below 0 - {}"
,
subscription
,
consumerId
,
permits
);
}
}
return
permitsToReduce
;
}
public
boolean
isWritable
()
{
...
...
pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
浏览文件 @
3e4e1276
...
...
@@ -149,7 +149,7 @@ public class PersistentDispatcherMultipleConsumers implements Dispatcher, ReadEn
}
private
void
readMoreEntries
()
{
if
(
totalAvailablePermits
>
0
&&
is
Unblocked
ConsumerAvailable
())
{
if
(
totalAvailablePermits
>
0
&&
is
AtleastOne
ConsumerAvailable
())
{
int
messagesToRead
=
Math
.
min
(
totalAvailablePermits
,
readBatchSize
);
if
(!
messagesToReplay
.
isEmpty
())
{
...
...
@@ -258,7 +258,7 @@ public class PersistentDispatcherMultipleConsumers implements Dispatcher, ReadEn
log
.
debug
(
"[{}] Distributing {} messages to {} consumers"
,
name
,
entries
.
size
(),
consumerList
.
size
());
}
while
(
entriesToDispatch
>
0
&&
totalAvailablePermits
>
0
&&
is
Unblocked
ConsumerAvailable
())
{
while
(
entriesToDispatch
>
0
&&
totalAvailablePermits
>
0
&&
is
AtleastOne
ConsumerAvailable
())
{
Consumer
c
=
getNextConsumer
();
if
(
c
==
null
)
{
// Do nothing, cursor will be rewind at reconnection
...
...
@@ -271,7 +271,7 @@ public class PersistentDispatcherMultipleConsumers implements Dispatcher, ReadEn
int
messagesForC
=
Math
.
min
(
Math
.
min
(
entriesToDispatch
,
c
.
getAvailablePermits
()),
MaxRoundRobinBatchSize
);
if
(
messagesForC
>
0
)
{
c
.
sendMessages
(
entries
.
subList
(
start
,
start
+
messagesForC
)
);
int
msgSent
=
c
.
sendMessages
(
entries
.
subList
(
start
,
start
+
messagesForC
)).
getRight
(
);
if
(
readType
==
ReadType
.
Replay
)
{
entries
.
subList
(
start
,
start
+
messagesForC
).
forEach
(
entry
->
{
...
...
@@ -280,7 +280,7 @@ public class PersistentDispatcherMultipleConsumers implements Dispatcher, ReadEn
}
start
+=
messagesForC
;
entriesToDispatch
-=
messagesForC
;
totalAvailablePermits
-=
m
essagesForC
;
totalAvailablePermits
-=
m
sgSent
;
}
}
...
...
@@ -357,7 +357,7 @@ public class PersistentDispatcherMultipleConsumers implements Dispatcher, ReadEn
// find next available unblocked consumer
int
unblockedConsumerIndex
=
consumerIndex
;
do
{
if
(
!
consumerList
.
get
(
unblockedConsumerIndex
).
isBlocked
(
))
{
if
(
isConsumerAvailable
(
consumerList
.
get
(
unblockedConsumerIndex
)
))
{
consumerIndex
=
unblockedConsumerIndex
;
return
consumerList
.
get
(
consumerIndex
++);
}
...
...
@@ -371,23 +371,26 @@ public class PersistentDispatcherMultipleConsumers implements Dispatcher, ReadEn
}
/**
* returns true only if {@link consumerList} has atleast one unblocked consumer
* returns true only if {@link consumerList} has atleast one unblocked consumer
and have available permits
*
* @return
*/
private
boolean
is
Unblocked
ConsumerAvailable
()
{
private
boolean
is
AtleastOne
ConsumerAvailable
()
{
if
(
consumerList
.
isEmpty
()
||
closeFuture
!=
null
)
{
// abort read if no consumers are connected or if disconnect is initiated
return
false
;
}
Iterator
<
Consumer
>
consumerIterator
=
consumerList
.
iterator
();
while
(
consumerIterator
.
hasNext
())
{
if
(!
consumerIterator
.
next
().
isBlocked
())
{
for
(
Consumer
consumer
:
consumerList
)
{
if
(
isConsumerAvailable
(
consumer
))
{
return
true
;
}
}
return
false
;
}
private
boolean
isConsumerAvailable
(
Consumer
consumer
)
{
return
consumer
!=
null
&&
!
consumer
.
isBlocked
()
&&
consumer
.
getAvailablePermits
()
>
0
;
}
@Override
public
synchronized
void
redeliverUnacknowledgedMessages
(
Consumer
consumer
)
{
...
...
pulsar-broker/src/main/java/com/yahoo/pulsar/broker/service/persistent/PersistentDispatcherSingleActiveConsumer.java
浏览文件 @
3e4e1276
...
...
@@ -199,7 +199,7 @@ public final class PersistentDispatcherSingleActiveConsumer implements Dispatche
readMoreEntries
(
currentConsumer
);
}
}
else
{
currentConsumer
.
sendMessages
(
entries
).
addListener
(
future
->
{
currentConsumer
.
sendMessages
(
entries
).
getLeft
().
addListener
(
future
->
{
if
(
future
.
isSuccess
())
{
// Schedule a new read batch operation only after the previous batch has been written to the socket
synchronized
(
PersistentDispatcherSingleActiveConsumer
.
this
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录