knative containers and golang goroutines? Background processes ...

119 views
Skip to first unread message

Sandy Walsh

unread,
Jul 29, 2019, 12:41:31 PM7/29/19
to Knative Users
I'm considering KNative/Google Cloud Run for some cron-like operations I need to perform. They will get triggered by an HTTP invocation. The invocation will return (likely with a 202) and continue running in the background via a golang goroutine.

But, I'm concerned that the runtime containers are destroyed when they're not handling HTTP requests. I could be part-way through my processing and get reaped.

Is there a way to tell knative/GCR to keep the container alive until I'm finished?

Mike Helmick

unread,
Jul 29, 2019, 12:45:13 PM7/29/19
to Sandy Walsh, Knative Users

Not currently. The runtime contract stipulates that a container will only keep running if it is handling a request.

There are 2 options that I would consider
1) Keeping the connection open while the processing is occurring
2) Using the knative eventing components to decouple the async nature of the request from the sync trigger.

mike h



--
You received this message because you are subscribed to the Google Groups "Knative Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knative-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/knative-users/6eba4626-2362-4d23-b445-19aece2db32e%40googlegroups.com.

Lionel Villard

unread,
Jul 29, 2019, 12:46:49 PM7/29/19
to Knative Users
One way is to configure the autoscaler minScale to be at least one (see https://knative.dev/docs/serving/configuring-the-autoscaler/). When the container is finished, remove the annotation.

Nemo Caviani

unread,
Jul 29, 2019, 12:57:51 PM7/29/19
to Sandy Walsh, Knative Users
currently Knative requires http connections to remain open while requests are processed.

We have been discussing options for supporting background jobs or async jobs under the following issue but it is still work in progress: https://github.com/knative/serving/issues/4522

On Mon, Jul 29, 2019 at 9:41 AM 'Sandy Walsh' via Knative Users <knativ...@googlegroups.com> wrote:
--

Ahmet Alp Balkan

unread,
Jul 29, 2019, 1:12:57 PM7/29/19
to Sandy Walsh, Knative Users
For your Cloud Run (managed version, not on GKE with Knative) question on Stackoverflow, I left an answer.

I believe the behavior of what happens when a request ends is different on Knative OSS implementation versus Google Cloud Run managed version (which scales CPU dynamically to ~0).

Ahmet Alp Balkan | Developer Advocate | github:@ahmetb | twitter:@ahmetb



On Mon, Jul 29, 2019 at 9:41 AM 'Sandy Walsh' via Knative Users <knativ...@googlegroups.com> wrote:
--

Scott Nichols

unread,
Jul 29, 2019, 1:34:36 PM7/29/19
to Ahmet Alp Balkan, Sandy Walsh, Knative Users
Also note the minscale to 1 trick will not work when the resource scales. 

-Scott


Message has been deleted

Sandy Walsh

unread,
Jul 30, 2019, 7:20:08 AM7/30/19
to Knative Users
Hmm, actually disregard that. I don't this it's really viable for this use case. 

CRun has a max runtime of 15 minutes (cannot be increased) and the billing model would make this prohibitive. 

I think I'll look at  k8s jobs next. 

Thanks again for your feedback everyone!

Matthew Moore

unread,
Jul 30, 2019, 10:53:01 AM7/30/19
to Sandy Walsh, Knative Users
(skimming, so sorry if I missed something)

Note that the 15 minutes used by Cloud Run on GKE is not a cap on the total request duration, but how quickly the server must start responding.

I believe that either GRPC streaming or websockets would hold the connection open for you, potentially for much longer than 15 minutes.


--
You received this message because you are subscribed to the Google Groups "Knative Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knative-user...@googlegroups.com.


--
Matthew Moore
Knative @ Google

Sandy Walsh

unread,
Jul 30, 2019, 11:43:48 AM7/30/19
to Matthew Moore, Knative Users
Thanks Matthew, that's an important nuance. Perhaps the docs should be explicit on that [1]

Something still smells wrong about holding a connection open that long. Perhaps DataFlow would be better?

Matthew Moore

unread,
Jul 30, 2019, 11:53:17 AM7/30/19
to Sandy Walsh, Knative Users
There are a number of batch options on GCP, but this probably isn't the place to discuss them.  If you want to start a thread with me, I can try to connect you with some folks.

There is also some discussion about async operations in Knative, but it's early days still (not sure if if was mentioned above).
-M
Reply all
Reply to author
Forward
0 new messages