Google-cloud-java: Should Publisher be shudown everytime ?

Created on 6 Mar 2019  路  4Comments  路  Source: googleapis/google-cloud-java

I have multiple scheduler which synchronize different kinds of data to different topics every 1 min.
Since my scheduler runs every 1 min either i have to either create an publisher on each invocation(and shutdown) of scheduler or i can maintain publisher as an spring bean and reuse the same.

Can you suggest which is better approach, cause i do see Deadline_Exceeded error intermittently ?

  • Although i know primary cause of Deadline_Exceeded is due to clogging pub sub client with too many messages but could this also impact it ?

Also i read in one of the issues #1751 if we do no call shutdown on publisher it does not exit from JVM and threads are still alive . Which threads are these , thread used by RPC to publish each message ?

  • Basically if i am publishing 100 messages then 100 threads are alive ?
pubsub question

Most helpful comment

@ayushj158 can you please try with below settings? Reason for below settings is since you are sending message every min, its better to batch in to bigger size close enough to transport window size which is 1mb, Used large number for element threshold so that batching threshold hits on number of bytes rather than number of messages.

    Publisher publish =
        Publisher.newBuilder("topic_name")
            .setBatchingSettings(
                BatchingSettings.newBuilder()
                    .setDelayThreshold(Duration.ofSeconds((50)))
                    .setRequestByteThreshold(1000000l)
                    .setElementCountThreshold(1000000l)
                    .build())
            .setRetrySettings(
                RetrySettings.newBuilder()
                    .setTotalTimeout(Duration.ofSeconds((50)))
                    .setInitialRetryDelay(Duration.ofMillis(1))
                    .setRetryDelayMultiplier(1)
                    .setMaxRetryDelay(Duration.ofSeconds((50)))
                    .setInitialRpcTimeout(Duration.ofSeconds((50)))
                    .setRpcTimeoutMultiplier(1)
                    .setMaxRpcTimeout(Duration.ofSeconds((120)))
                    .build())
            .build();

All 4 comments

@ayushj158 Its better to create client just once and keep reusing it. For DEADLINE_EXCEEDED, how many message do you send every 1 min? Are you running from your local machine or from GCP?

It can range from 100K-600K/min.... I am running on an on premise Linux machine with enough computing power. Also tried to use custom retry settings but i am not able to restrict the failures to zero, intermittently i see 10-15 messages being failed.

  • Also i am using load shedding to minimize the failures #3867

BTW what is the effect of publisher being open in JVM , how many and which threads are not being released?

 RetrySettings retrySettings = RetrySettings.newBuilder()
                .setInitialRetryDelay(Duration.ofMillis(5))
                .setRetryDelayMultiplier(2)
                .setMaxRetryDelay(Duration.ofMillis(Long.MAX_VALUE))
                .setTotalTimeout(Duration.ofSeconds(10))
                .setInitialRpcTimeout(Duration.ofSeconds(10))
                .setMaxRpcTimeout(Duration.ofSeconds(10))
                .build();

@ayushj158 can you please try with below settings? Reason for below settings is since you are sending message every min, its better to batch in to bigger size close enough to transport window size which is 1mb, Used large number for element threshold so that batching threshold hits on number of bytes rather than number of messages.

    Publisher publish =
        Publisher.newBuilder("topic_name")
            .setBatchingSettings(
                BatchingSettings.newBuilder()
                    .setDelayThreshold(Duration.ofSeconds((50)))
                    .setRequestByteThreshold(1000000l)
                    .setElementCountThreshold(1000000l)
                    .build())
            .setRetrySettings(
                RetrySettings.newBuilder()
                    .setTotalTimeout(Duration.ofSeconds((50)))
                    .setInitialRetryDelay(Duration.ofMillis(1))
                    .setRetryDelayMultiplier(1)
                    .setMaxRetryDelay(Duration.ofSeconds((50)))
                    .setInitialRpcTimeout(Duration.ofSeconds((50)))
                    .setRpcTimeoutMultiplier(1)
                    .setMaxRpcTimeout(Duration.ofSeconds((120)))
                    .build())
            .build();

@ajaaym Perfect thanks for the quick tip Ajay, i am gonna try this . :+1: :+1:

Was this page helpful?
0 / 5 - 0 ratings