question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pubsub messages take 30 seconds to publish

See original GitHub issue

I’ve created a cloudfunction which transforms a xml request into json entities and then publishes the entites to pubsub one by one. The problem is that it takes around 30 seconds (sometimes more) to publish the first entity. after the first entity is published the others are published instantly. In our dataflow we depend on fast communication times which makes this a big problem for us. I already tried to disable the batching but it had the same behaviour as before. Also i tried the same thing with python in it worked without any delay.

const topic = pubsub.topic("topic", {
        batching: {
            maxMessages: 1
        },
    });

    const attributes = {
        operation: operation
    };

    jsonEntities.forEach((entity) => {
        const publisher = topic.publisher;
        publisher.publish(Buffer.from(JSON.stringify(entity), attributes));

    });
    console.log(`after ${new Date().toLocaleString()}`);

    res.status(200);

Environment details

  • Node.js version: 8
  • @google-cloud/pubsub version: 0.28.1

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JustinBeckwithcommented, Apr 24, 2019

Oh fascinating! If the cloud function is loaded, and the library has been require’d, I don’t think we have a bug or have done any investigation here. Sounds like an adventure @callmehiphop!

0reactions
fabianrindlisbachercommented, Apr 30, 2019

if i it like that it works just fine for some reason.

const topic = pubsub.topic("topic", {
        batching: {
            maxMessages: 1000
        },
    });

    const attributes = {
        operation: operation
    };

    var itemsProcessed = 0;
    messages.forEach((message) => {
        const publisher = topic.publisher;
        publisher.publish(Buffer.from(JSON.stringify(message), attributes)).then((publishRes) => {
            console.log(stockRes, new Date().toLocaleString());
            itemsProcessed++;
            if (itemsProcessed === messages.length) {
                console.log(`after $s{new Date().toLocaleString()}`);

                res.status(200).send(JSON.stringify(messages));
            }
        });
    });

I guess it’s no issue of your library. I’ll close this Issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publish messages to topics | Cloud Pub/Sub - Google Cloud
Before you begin; Message format; Publish messages. Use attributes; Use ... By default a publisher will retry for 60 seconds, with an initial...
Read more >
Cloud Function is taking too long to send a message to PubSub
The message does get published to the PubSub queue, however, it is pushed ~90 seconds after the image processing is complete.
Read more >
pubsub: so slow when publish message · Issue #1961 - GitHub
Hi I am new with google pubsub, why so slow when publish message to topic? Sometime it only takes 20-30ms, but sometimes can...
Read more >
pubsub - Go Packages
Package pubsub provides an easy way to publish and receive Google Cloud Pub/Sub ... For use cases where message processing exceeds 30 minutes,...
Read more >
Publishing first messages takes a long time (10 to 15 seconds)!
to Google Cloud Pub/Sub Discussions. Hi when I publish messages in a loop, the first messages is published in 10 to 15 seconds,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found