-
Notifications
You must be signed in to change notification settings - Fork 514
Add metadata property to configure Batching in Pulsar #1707
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
Changes from all commits
7bb037c
dea0a4c
e80ea4e
7183e10
789908c
95b7358
8ec99f2
524e533
b585453
1affeae
9f1daf3
4daff00
2d8077e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,18 @@ import ( | |
) | ||
|
||
const ( | ||
host = "host" | ||
consumerID = "consumerID" | ||
enableTLS = "enableTLS" | ||
deliverAt = "deliverAt" | ||
deliverAfter = "deliverAfter" | ||
disableBatching = "disableBatching" | ||
tenant = "tenant" | ||
namespace = "namespace" | ||
persistent = "persistent" | ||
host = "host" | ||
consumerID = "consumerID" | ||
enableTLS = "enableTLS" | ||
deliverAt = "deliverAt" | ||
deliverAfter = "deliverAfter" | ||
disableBatching = "disableBatching" | ||
batchingMaxPublishDelay = "batchingMaxPublishDelay" | ||
batchingMaxSize = "batchingMaxSize" | ||
batchingMaxMessages = "batchingMaxMessages" | ||
tenant = "tenant" | ||
namespace = "namespace" | ||
persistent = "persistent" | ||
|
||
defaultTenant = "public" | ||
defaultNamespace = "default" | ||
|
@@ -50,6 +53,13 @@ const ( | |
topicFormat = "%s://%s/%s/%s" | ||
persistentStr = "persistent" | ||
nonPersistentStr = "non-persistent" | ||
|
||
// defaultBatchingMaxPublishDelay init default for maximum delay to batch messages. | ||
defaultBatchingMaxPublishDelay = 10 * time.Millisecond | ||
// defaultMaxMessages init default num of entries in per batch. | ||
defaultMaxMessages = 1000 | ||
// defaultMaxBatchSize init default for maximum number of bytes per batch. | ||
defaultMaxBatchSize = 128 * 1024 | ||
) | ||
|
||
type Pulsar struct { | ||
|
@@ -92,7 +102,30 @@ func parsePulsarMetadata(meta pubsub.Metadata) (*pulsarMetadata, error) { | |
} | ||
m.DisableBatching = disableBatching | ||
} | ||
|
||
m.BatchingMaxPublishDelay = defaultBatchingMaxPublishDelay | ||
if val, ok := meta.Properties[batchingMaxPublishDelay]; ok { | ||
batchingMaxPublishDelay, err := formatDuration(val) | ||
if err != nil { | ||
return nil, errors.New("pulsar error: invalid value for batchingMaxPublishDelay") | ||
} | ||
m.BatchingMaxPublishDelay = batchingMaxPublishDelay | ||
} | ||
m.BatchingMaxMessages = defaultMaxMessages | ||
if val, ok := meta.Properties[batchingMaxMessages]; ok { | ||
saber-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
batchingMaxMessages, err := strconv.ParseUint(val, 10, 64) | ||
if err != nil { | ||
return nil, errors.New("pulsar error: invalid value for batchingMaxMessages") | ||
} | ||
m.BatchingMaxMessages = uint(batchingMaxMessages) | ||
} | ||
m.BatchingMaxSize = defaultMaxBatchSize | ||
if val, ok := meta.Properties[batchingMaxSize]; ok { | ||
batchingMaxSize, err := strconv.ParseUint(val, 10, 64) | ||
if err != nil { | ||
return nil, errors.New("pulsar error: invalid value for batchingMaxSize") | ||
} | ||
m.BatchingMaxSize = uint(batchingMaxSize) | ||
} | ||
if val, ok := meta.Properties[persistent]; ok && val != "" { | ||
per, err := strconv.ParseBool(val) | ||
if err != nil { | ||
|
@@ -179,8 +212,11 @@ func (p *Pulsar) Publish(req *pubsub.PublishRequest) error { | |
if cache == nil { | ||
p.logger.Debugf("creating producer for topic %s, full topic name in pulsar is %s", req.Topic, topic) | ||
producer, err = p.client.CreateProducer(pulsar.ProducerOptions{ | ||
Topic: topic, | ||
DisableBatching: p.metadata.DisableBatching, | ||
Topic: topic, | ||
DisableBatching: p.metadata.DisableBatching, | ||
BatchingMaxPublishDelay: p.metadata.BatchingMaxPublishDelay, | ||
BatchingMaxMessages: p.metadata.BatchingMaxMessages, | ||
BatchingMaxSize: p.metadata.BatchingMaxSize, | ||
}) | ||
if err != nil { | ||
return err | ||
|
@@ -317,3 +353,14 @@ func (p *Pulsar) formatTopic(topic string) string { | |
} | ||
return fmt.Sprintf(topicFormat, persist, p.metadata.Tenant, p.metadata.Namespace, topic) | ||
} | ||
|
||
func formatDuration(durationString string) (time.Duration, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1172 Is there a better way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saber-wang we can make it simpler by always expecting a number. The metadata can be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @berndverst this comment was still pending. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1172 Need to change to such a design? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would have been cleaner and simpler but Bernd has already approved/merged this PR. If we have enough consensus, we can create another PR on top to change that I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shubham1172 I don't have a better idea. I can create a new rp to modify it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @saber-wang. Let's see what Bernd/@daixiang0 have to say. |
||
if val, err := strconv.Atoi(durationString); err == nil { | ||
return time.Duration(val) * time.Millisecond, nil | ||
} | ||
|
||
// Convert it by parsing | ||
d, err := time.ParseDuration(durationString) | ||
|
||
return d, err | ||
} |
Uh oh!
There was an error while loading. Please reload this page.