Conversation
The watchdog can be imported by a Go template in order to avoid any hop over HTTP. On the plus side - RAM looks to be much smaller as low as 2mb total usage vs the two processes. On the downside, it's not possible or practical to do stderr/stdout prefixing due to no process boundary between the watchdog and the handler process. A new template and Dockerfile will be required to support the changes. Builds may be marginally slower since they have to import the watchdog as an "SDK". Every push will be a single layer binary so this will also take longer vs a tiny Go binary plus the watchdog. Initial testing in Kubernetes with a modified template appears to work as expected. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR introduces an "inproc" (in-process) mode for Golang functions, allowing the watchdog and function handler to run in a single process instead of spawning separate processes. This architectural change aims to reduce total RAM usage and potentially improve roundtrip latency for function invocations, with initial testing showing approximately 2-4 MB RAM usage compared to 11 MB for traditional separate-process mode.
Key changes:
- Adds new
ModeInprocoperational mode with corresponding configuration and executor - Refactors main watchdog logic from
main.gointopkg/watchdog.goto enable reusability - Changes package structure from
maintopkgfor core watchdog components
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| vendor/modules.txt | Adds google/uuid dependency for the new inproc mode |
| go.mod | Removes gorilla/mux from indirect dependencies |
| config/config_modes.go | Defines ModeInproc constant and adds "inproc" mode support |
| config/config.go | Adds Handler field and allows empty fprocess for inproc/static modes |
| config/config_test.go | Tests that inproc mode allows missing fprocess configuration |
| executor/inproc_runner.go | Implements InprocRunner for executing handlers in-process |
| pkg/watchdog.go | Refactored watchdog logic extracted from main.go into reusable package |
| main.go | Simplified to use new pkg.Watchdog with minimal bootstrapping code |
| requesthandler_test.go | Updates package from main to pkg and adjusts health handler calls |
| readiness_test.go | Updates package from main to pkg |
| readiness.go | Updates package from main to pkg |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
Reviewed by opencode / Big Pickle.. no significant issues detected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add "inproc" mode for Golang functions
Motivation and Context
Reduce total RAM usage by running a single process for the watchdog and the handler of a function (only possible with Go)
Roundtrip latency may also be improved for function invocations.
How Has This Been Tested?
Initial testing in Kubernetes with a modified template appears to work as expected.
To achieve a similar effect to prefixing each logged line with a Call ID bespoke code will be required:
Initial RAM usage showed as
2Miand rose over time to4MiThe
printerfunction from the store is showing about11Miof usage and does very little in and of itself other than logging the incoming HTTP request:Custom template that imports the new watchdog "SDK":
https://github.com/openfaas/golang-http-template/blob/inproc/template/golang-middleware-inproc/main.go
Types of changes
On the plus side - RAM looks to be much smaller as low as 2mb total usage vs the two processes.
On the downside, it's not possible or practical to do stderr/stdout prefixing due to no process boundary between the watchdog and the handler process.
A new template and Dockerfile will be required to support the changes. Builds may be marginally slower since they have to import the watchdog as an "SDK".
Every push will be a single layer binary so this will also take longer vs a tiny Go binary plus the watchdog.
Checklist:
The change will have to be explained and documented as an alternative. Unless it becomes the default, I can't imagine uptake being large other than for internal use and with select customers who learn about it from us.