Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using background tasks pkgs #158

Open
yarelm opened this issue Sep 2, 2021 · 2 comments
Open

Using background tasks pkgs #158

yarelm opened this issue Sep 2, 2021 · 2 comments
Labels
question Further information is requested

Comments

@yarelm
Copy link

yarelm commented Sep 2, 2021

Hya,
Using Cloud Run (in Go for example), occasionally there is a need to use a 3rd party pkg that does some background processing. Sometimes, this processing is done out of the request context.

For example, I'm using the (https://github.com/google/go-metrics-stackdriver) pkg for sending metrics to stackdriver. It launches a goroutine that periodically sends pending metrics. This is done async to the request flow.

I understand Cloud Run can throttle the CPU to 0 when not handling requests - I am intrigued about how does that affects such use cases. In some cases, I can be OK with my periodic handling being suspended for a while. Just trying to better understand what to expect.

I know the best practice is to avoid background jobs, however, I believe in many use cases it's a requirement (I prefer to not re-write plumbing logic when I don't have to 😄 )

Cheers

@ahmetb
Copy link
Owner

ahmetb commented Sep 2, 2021

Most metrics libraries have flush() methods that can be called before container shuts down via a SIGTERM signal. Consider using that facility.

There's a feature in preview that keeps the CPU always on in the background but it has different pricing and not publicly available yet.

@ahmetb ahmetb added the question Further information is requested label Sep 2, 2021
@jokester
Copy link

I'm guessing that CPU throttling is different to terminating the process? But I don't see much document about what people should do in a process being throttled or "suspended". To be more specific I personally have no idea what to do with DB connection pools.

BTW the "always allocate CPU" flag is in GA now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants
@ahmetb @jokester @yarelm and others