Skip to content

Commit 3aed5c5

Browse files
committed
Add maxprocs to the agent
1 parent d76b252 commit 3aed5c5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cli/agent.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"time"
1818

1919
"cloud.google.com/go/compute/metadata"
20+
"go.uber.org/automaxprocs/maxprocs"
2021
"golang.org/x/xerrors"
2122
"gopkg.in/natefinch/lumberjack.v2"
2223
"tailscale.com/util/clientmetric"
@@ -162,6 +163,16 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
162163
sinks = append(sinks, sloghuman.Sink(logWriter))
163164
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
164165

166+
// This can improve the performance of Coder inside of a container.
167+
// See: https://github.com/uber-go/automaxprocs
168+
undoMacProcs, err := maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
169+
logger.Debug(ctx, fmt.Sprintf(format, args...))
170+
}))
171+
if err != nil {
172+
return xerrors.Errorf("set maxprocs: %w", err)
173+
}
174+
defer undoMacProcs()
175+
165176
version := buildinfo.Version()
166177
logger.Info(ctx, "agent is starting now",
167178
slog.F("url", r.agentURL),

cli/server.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,13 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
326326

327327
// This can improve the performance of Coder inside of a container.
328328
// See: https://github.com/uber-go/automaxprocs
329-
maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
329+
undoMacProcs, err := maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
330330
logger.Debug(ctx, fmt.Sprintf(format, args...))
331331
}))
332+
if err != nil {
333+
return xerrors.Errorf("set maxprocs: %w", err)
334+
}
335+
defer undoMacProcs()
332336

333337
// Register signals early on so that graceful shutdown can't
334338
// be interrupted by additional signals. Note that we avoid

0 commit comments

Comments
 (0)