Skip to content

Potential (CPU) performance improvement when publishing #2295

@MV-GH

Description

@MV-GH

I was profiling a pubsub benchmark and I saw a potential improvement. Each publish it parses the topicName. 90% of publish CPU time is spent on this. 30% of total CPU during my profiling. One could lift this up into the publisher and pass TopicName directly into PubsubMessageWrapper in the publish

image

Short Repro

val sessionSampleMsg = """{"website":"https://minty-modernist.name","domain":"limp-effector.com","job":{"title":"Investor Creative Administrator","descriptor":"Customer","area":"Accountability","type":"Consultant","company":"Bailey - Ledner"},"uuid":"1ef60952-c540-47ad-97c3-e923e20faafc","objectId":"67643b6bac95a0492808f66b"}"""

val samplePubsubMsg = PubsubMessage.newBuilder()
    .setData(ByteString.copyFromUtf8(sessionSampleMsg))
    .build()

val testTopic = "projects/test/topics/pst-test"
val optimalPublisher = Publisher.newBuilder(testTopic)

fun startProducing(publisher: Publisher) {
    while (true){
        publisher.publish(samplePubsubMsg)
    }
}

fun main() {
  startProducing(optimalPublisher)
}

Profile background

Was run on 2vpcu xeon + 4GB ram, LTS JDK 21

I have included the profile, see below
optimal-producer.zip

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the googleapis/java-pubsub API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions