title: Google Cloud Functions & PubSub - delay after idling
body: <p>I'm triggering an HTTP Cloud Function, which then publishes a message to my PubSub topic. When publishing every few seconds, this works quite quickly, usually with &lt;1s delay. However, if I am NOT publishing anything for a while (say 5 minutes), the  publishing happens with a long delay (~20s).</p>
  
  <p>How can I make this consistently quick? Ideas:</p>
  
  <ul>
  <li>Somehow configure Pub/Sub publisher to do so immediatelly. Couldn't find such argument in API documentation, though.</li>
  <li>Change the publisher function.</li>
  </ul>
  
  <p><strong>Publisher function:</strong></p>
  
  <pre><code>"use strict";
  const PubSub = require("@google-cloud/pubsub");
  const pubsub = PubSub({
      projectId: "pubsub-forwarders"
  });
  
  exports.testFunction = function testFunction(req, res) {
      publishMessage("testtopic", "testmessage");
      res.status(200).send();
  }
  
  function publishMessage(topicName, data) {
      const topic = pubsub.topic(topicName);
      const publisher = topic.publisher();
      const dataBuffer = Buffer.from(data);
  
      return publisher.publish(dataBuffer)
          .then((results) =&gt; {
              console.log("Message", JSON.stringify(results), "published.");
              return JSON.stringify(results);
      });
  }
  </code></pre>
  
  <p><strong>Cloud functions logs:</strong></p>
  
  <pre><code>16:57:05.938 Function execution started
  16:57:05.948 Function execution took 11 ms, finished with status code: 200
  16:57:22.987 Message "179492329652563" published.
  </code></pre>
  
  <p>Thanks a lot!</p>