0
votes

I have a simple Spring boot application hosted in Google Cloud Run which publishes a Google Pub/Sub message to a topic in the same project.

This is taking a long time for about 5 min roughly. Below is the code that I use to publish the Google Pub/Sub message. But the same was working fine with no delay in App Engine environment.

ApiFuture<String> messageIdFuture = com.google.cloud.pubsub.v1.Publisher.publish(pubsubMessage);
            ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<String>() {
                @Override
                public void onFailure(Throwable throwable) {
                    if (throwable instanceof ApiException) {
                        ApiException apiException = ((ApiException) throwable);
                        // details on the API exception
                        log.error("APIException Status Code: {}", apiException.getStatusCode().getCode());
                        log.error("APIException is Retryable: {}", apiException.isRetryable());
                    }
                    log.error("Error publishing message: {}", pubSubMsg);
                }
                @Override
                public void onSuccess(String messageId) {
                    log.info("Success msg after publish: {}", messageId);
                }
            }, MoreExecutors.directExecutor());

How can I overcome this delay in publishing the Pub/Sub message?

1
When you are handling a request in Cloud Run, you want to publish a message in PubSub, correct? And it takes 5 minutes to publish it, right? Can you share more of your code? I would like to see if you wait the ApiFuture or if you let it running in background.guillaume blaquiere
That is the full code i use for publishing pubsub message. I'm using docker to containerize and deploy into cloud runJefila
What call this code? you should have a function around. I would like to understand the context of the call to this piece of codeguillaume blaquiere

1 Answers

0
votes

If I remember correctly, Spring Boot creates a JAR file that contains nested JARs. In Cloud Run, these files get unpacked during startup, and this can impact on the run time.

Google App Engine is a managed service; you have no control over the run time, whereas, Cloud Run containers need to be tweaked to optimise the environment.

Based on this, I expect you will need to optimise how your app runs in the container. Are you using a Multi-Stage Build? You can also try using a Jib plugin to containerise your application and see if that improves your timings.

I am not overly familiar with Spring Boot, but this article discusses how to containerise your code for best performance. These links have some useful information on Jib Plugin configuration, jib extensions on GitHub and this blog post.