Skip to content

Commit d4be5e5

Browse files
authored
pubsub: make Subscriber logs less chatty (#1748)
Also use text formatting so we don't unnecessarily allocate Strings when not logging. Fixes #1686.
1 parent fc9f9f7 commit d4be5e5

4 files changed

Lines changed: 24 additions & 34 deletions

File tree

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/MessageDispatcher.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ public void processReceivedMessages(List<com.google.pubsub.v1.ReceivedMessage> r
273273
ackHandlers.add(new AckHandler(pubsubMessage.getAckId(), messageSize));
274274
}
275275
Instant expiration = now.plus(messageDeadlineSeconds * 1000);
276-
logger.log(Level.INFO, "Received " + responseMessages.size() + " messages at " + now);
276+
logger.log(
277+
Level.FINER, "Received {0} messages at {1}", new Object[] {responseMessages.size(), now});
277278

278279
messagesWaiter.incrementPendingMessages(responseMessages.size());
279280
Iterator<AckHandler> acksIterator = ackHandlers.iterator();
@@ -364,13 +365,9 @@ public void run() {
364365
((long) Math.ceil(now.plus(ackExpirationPadding).plus(500).getMillis() / 1000.0))
365366
* 1000L);
366367
logger.log(
367-
Level.INFO,
368-
"Running alarm sent outstanding acks, at now time: "
369-
+ now
370-
+ ", with cutover time: "
371-
+ cutOverTime
372-
+ ", padding: "
373-
+ ackExpirationPadding);
368+
Level.FINER,
369+
"Running alarm sent outstanding acks, at time: {0}, with cutover time: {1}, padding: {2}",
370+
new Object[] {now, cutOverTime, ackExpirationPadding});
374371
Instant nextScheduleExpiration = null;
375372
List<PendingModifyAckDeadline> modifyAckDeadlinesToSend = new ArrayList<>();
376373

@@ -421,12 +418,9 @@ public void run() {
421418

422419
if (nextScheduleExpiration != null) {
423420
logger.log(
424-
Level.INFO,
425-
"Scheduling based on outstanding, now time: "
426-
+ now
427-
+ ", "
428-
+ "next schedule time: "
429-
+ nextScheduleExpiration);
421+
Level.FINER,
422+
"Scheduling based on outstanding, at time: {0}, next scheduled time: {1}",
423+
new Object[] {now, nextScheduleExpiration});
430424
setupNextAckDeadlineExtensionAlarm(nextScheduleExpiration);
431425
}
432426
}
@@ -438,13 +432,11 @@ private void setupNextAckDeadlineExtensionAlarm(Instant expiration) {
438432
try {
439433
if (nextAckDeadlineExtensionAlarmTime.isAfter(possibleNextAlarmTime)) {
440434
logger.log(
441-
Level.INFO,
442-
"Scheduling next alarm time: "
443-
+ possibleNextAlarmTime
444-
+ ", last alarm set to time: "
445-
+ nextAckDeadlineExtensionAlarmTime);
435+
Level.FINER,
436+
"Scheduling next alarm time: {0}, previous alarm time: {1}",
437+
new Object[] {possibleNextAlarmTime, nextAckDeadlineExtensionAlarmTime});
446438
if (ackDeadlineExtensionAlarm != null) {
447-
logger.log(Level.INFO, "Canceling previous alarm");
439+
logger.log(Level.FINER, "Canceling previous alarm");
448440
ackDeadlineExtensionAlarm.cancel(false);
449441
}
450442

@@ -475,7 +467,7 @@ private void processOutstandingAckOperations(
475467
if (!pendingAcks.isEmpty()) {
476468
try {
477469
acksToSend = new ArrayList<>(pendingAcks);
478-
logger.log(Level.INFO, "Sending {0} acks", acksToSend.size());
470+
logger.log(Level.FINER, "Sending {0} acks", acksToSend.size());
479471
} finally {
480472
pendingAcks.clear();
481473
}
@@ -488,7 +480,7 @@ private void processOutstandingAckOperations(
488480
for (String ackId : pendingNacks) {
489481
nacksToSend.addAckId(ackId);
490482
}
491-
logger.log(Level.INFO, "Sending {0} nacks", pendingNacks.size());
483+
logger.log(Level.FINER, "Sending {0} nacks", pendingNacks.size());
492484
} finally {
493485
pendingNacks.clear();
494486
}

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/PollingSubscriberConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public PollingSubscriberConnection(
9595

9696
@Override
9797
protected void doStart() {
98-
logger.log(Level.INFO, "Starting subscriber.");
98+
logger.config("Starting subscriber.");
9999
initialize();
100100
notifyStarted();
101101
}

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/StreamingSubscriberConnection.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public StreamingSubscriberConnection(
9696

9797
@Override
9898
protected void doStart() {
99-
logger.log(Level.INFO, "Starting subscriber.");
99+
logger.config("Starting subscriber.");
100100
initialize();
101101
notifyStarted();
102102
}
@@ -134,13 +134,13 @@ public void onNext(StreamingPullResponse response) {
134134

135135
@Override
136136
public void onError(Throwable t) {
137-
logger.log(Level.INFO, "Terminated streaming with exception", t);
137+
logger.log(Level.WARNING, "Terminated streaming with exception", t);
138138
errorFuture.setException(t);
139139
}
140140

141141
@Override
142142
public void onCompleted() {
143-
logger.log(Level.INFO, "Streaming pull terminated successfully!");
143+
logger.fine("Streaming pull terminated successfully!");
144144
errorFuture.set(null);
145145
}
146146
}
@@ -157,11 +157,9 @@ private void initialize() {
157157
CallOptions.DEFAULT.withCallCredentials(MoreCallCredentials.from(credentials))),
158158
responseObserver));
159159
logger.log(
160-
Level.INFO,
161-
"Initializing stream to subscription "
162-
+ subscription
163-
+ " with deadline "
164-
+ messageDispatcher.getMessageDeadlineSeconds());
160+
Level.FINER,
161+
"Initializing stream to subscription {0} with deadline {1}",
162+
new Object[] {subscription, messageDispatcher.getMessageDeadlineSeconds()});
165163
requestObserver.onNext(
166164
StreamingPullRequest.newBuilder()
167165
.setSubscription(subscription)

google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/spi/v1/Subscriber.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public void close() throws IOException {
321321

322322
@Override
323323
protected void doStart() {
324-
logger.log(Level.INFO, "Starting subscriber group.");
324+
logger.log(Level.FINE, "Starting subscriber group.");
325325
// Streaming pull is not enabled on the service yet.
326326
// startStreamingConnections();
327327
startPollingConnections();
@@ -395,8 +395,8 @@ public void run() {
395395
if (streamAckDeadlineSeconds != possibleStreamAckDeadlineSeconds) {
396396
streamAckDeadlineSeconds = possibleStreamAckDeadlineSeconds;
397397
logger.log(
398-
Level.INFO,
399-
"Updating stream deadline to {} seconds.",
398+
Level.FINER,
399+
"Updating stream deadline to {0} seconds.",
400400
streamAckDeadlineSeconds);
401401
for (StreamingSubscriberConnection subscriberConnection :
402402
streamingSubscriberConnections) {

0 commit comments

Comments
 (0)