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

Reduce memory footprint by reordering struct elements #804

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type stateStore interface {
// Unenroll results in running agent entering idle state, non managed non standalone.
// For it to be operational again it needs to be either enrolled or reconfigured.
type Unenroll struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 72 pointer bytes could be 56

dispatcher pipeline.Router
stateStore stateStore
log *logger.Logger
emitter pipeline.EmitterFunc
dispatcher pipeline.Router
closers []context.CancelFunc
stateStore stateStore
}

// NewUnenroll creates a new Unenroll handler.
Expand Down
10 changes: 5 additions & 5 deletions internal/pkg/agent/application/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ var (

// Upgrader performs an upgrade
type Upgrader struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 120 pointer bytes could be 96

agentInfo *info.AgentInfo
reporter stateReporter
caps capabilities.Capability
reexec reexecManager
acker acker
settings *artifact.Config
agentInfo *info.AgentInfo
log *logger.Logger
closers []context.CancelFunc
reexec reexecManager
acker acker
reporter stateReporter
upgradeable bool
caps capabilities.Capability
}

// Action is the upgrade action state.
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/operation/operation_retryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
// if nth operation fails all preceding are retried as well
type retryableOperations struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 40 pointer bytes could be 24

logger *logger.Logger
operations []operation
retryConfig *retry.Config
operations []operation
}

func newRetryableOperations(
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/stateresolver/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func (s *state) String() string {
}

type active struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 272 pointer bytes could be 256

LastChange stateChange
Program program.Program
LastModified time.Time
Identifier string
Program program.Program
LastChange stateChange
}

func (s *active) String() string {
Expand Down
12 changes: 6 additions & 6 deletions internal/pkg/composable/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import (
)

type pod struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 120 pointer bytes could be 104

logger *logp.Logger
cleanupTimeout time.Duration
comm composable.DynamicProviderComm
scope string
config *Config
metagen metadata.MetaGen
watcher kubernetes.Watcher
nodeWatcher kubernetes.Watcher
comm composable.DynamicProviderComm
metagen metadata.MetaGen
namespaceWatcher kubernetes.Watcher
config *Config
logger *logp.Logger
scope string
cleanupTimeout time.Duration

// Mutex used by configuration updates not triggered by the main watcher,
// to avoid race conditions between cross updates and deletions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import "github.com/elastic/elastic-agent-autodiscover/kubernetes"

// Config for kubernetes_leaderelection provider
type Config struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 40 pointer bytes could be 24

KubeConfig string `config:"kube_config"`
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
KubeConfig string `config:"kube_config"`

// Name of the leaderelection lease
LeaderLease string `config:"leader_lease"`

KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
}

// InitDefaults initializes the default values for the config.
Expand Down
51 changes: 24 additions & 27 deletions internal/pkg/core/plugin/process/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,32 @@ var (

// Application encapsulates a concrete application ran by elastic-agent e.g Beat.
type Application struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 296 pointer bytes could be 264

bgContext context.Context
id string
name string
pipelineID string
logLevel string
desc *app.Descriptor
srv *server.Server
srvState *server.ApplicationState
limiter *tokenbucket.Bucket
startContext context.Context
tag app.Taggable
state state.State
reporter state.Reporter
watchClosers map[int]context.CancelFunc
state state.State
startContext context.Context
statusReporter status.Reporter
monitor monitoring.Monitor
reporter state.Reporter
tag app.Taggable
bgContext context.Context
srvState *server.ApplicationState
limiter *tokenbucket.Bucket
srv *server.Server
desc *app.Descriptor
restartCanceller context.CancelFunc
logger *logger.Logger
watchClosers map[int]context.CancelFunc
processConfig *process.Config
restartConfig map[string]interface{}

name string
id string
pipelineID string
logLevel string

uid int
gid int

monitor monitoring.Monitor
statusReporter status.Reporter

processConfig *process.Config

logger *logger.Logger

appLock sync.Mutex
restartCanceller context.CancelFunc
restartConfig map[string]interface{}
appLock sync.Mutex
}

// ArgsDecorator decorates arguments before calling an application
Expand All @@ -79,8 +77,8 @@ func NewApplication(
logger *logger.Logger,
reporter state.Reporter,
monitor monitoring.Monitor,
statusController status.Controller) (*Application, error) {

statusController status.Controller,
) (*Application, error) {
s := desc.ProcessSpec()
uid, gid, err := s.UserGroup()
if err != nil {
Expand Down Expand Up @@ -157,7 +155,6 @@ func (a *Application) Stop() {

a.logger.Error(err)
}

}

a.appLock.Lock()
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/core/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func FromProto(s proto.StateObserved_Status) Status {
// State wraps the process state and application status.
type State struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 40 pointer bytes could be 24

ProcessInfo *process.Info
Status Status
Message string
Payload map[string]interface{}
Message string
Status Status
}

// Reporter is interface that is called when a state is changed.
Expand Down
28 changes: 14 additions & 14 deletions internal/pkg/core/status/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ func (s AgentStatusCode) String() string {

// AgentApplicationStatus returns the status of specific application.
type AgentApplicationStatus struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 64 pointer bytes could be 48

Payload map[string]interface{}
ID string
Name string
Status state.Status
Message string
Payload map[string]interface{}
Status state.Status
}

// AgentStatus returns the overall status of the Elastic Agent.
type AgentStatus struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 72 pointer bytes could be 48

Status AgentStatusCode
UpdateTime time.Time
Message string
Applications []AgentApplicationStatus
UpdateTime time.Time
Status AgentStatusCode
}

// Controller takes track of component statuses.
Expand All @@ -68,15 +68,15 @@ type Controller interface {
}

type controller struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 104 pointer bytes could be 88

mx sync.Mutex
status AgentStatusCode
message string
updateTime time.Time
log *logger.Logger
reporters map[string]*reporter
appReporters map[string]*reporter
log *logger.Logger
stateID string
message string
agentID string
status AgentStatusCode
mx sync.Mutex
}

// NewController creates a new reporter.
Expand Down Expand Up @@ -272,15 +272,15 @@ type Reporter interface {
}

type reporter struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 80 pointer bytes could be 48

name string
mx sync.Mutex
isPersistent bool
isRegistered bool
status state.Status
message string
payload map[string]interface{}
unregisterFunc func()
notifyChangeFunc func()
message string
name string
status state.Status
mx sync.Mutex
isRegistered bool
isPersistent bool
}

// Update updates the status of a component.
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/crypto/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
// Option is the default options used to generate the encrypt and decrypt writer.
// NOTE: the defined options need to be same for both the Reader and the writer.
type Option struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 40 pointer bytes could be 8

Generator bytesGen
IterationsCount int
KeyLength int
SaltLength int
IVLength int
Generator bytesGen

// BlockSize must be a factor of aes.BlockSize
BlockSize int
Expand Down
15 changes: 7 additions & 8 deletions internal/pkg/fleetapi/acker/retrier/retrier.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ type Option func(*Retrier)

// Retrier implements retrier for actions acks
type Retrier struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 96 pointer bytes could be 48

log *logger.Logger
acker BatchAcker // AckBatch provider
log *logger.Logger

initialRetryInterval time.Duration // initial retry interval
maxRetryInterval time.Duration // max retry interval
maxRetries int // configurable maxNumber of retries per action
doneCh chan struct{} // signal channel to kickoff retry loop if not running
kickCh chan struct{} // signal channel when retry loop is done

actions []fleetapi.Action // pending actions
mx sync.Mutex

kickCh chan struct{} // signal channel to kickoff retry loop if not running
maxRetryInterval time.Duration // max retry interval
maxRetries int // configurable maxNumber of retries per action
initialRetryInterval time.Duration // initial retry interval

doneCh chan struct{} // signal channel when retry loop is done
mx sync.Mutex
}

// New creates new instance of retrier
Expand Down Expand Up @@ -173,7 +173,6 @@ func (r *Retrier) runRetries(ctx context.Context) {
default:
}
r.log.Debug("ack retrier: exit retry loop")

}

func (r *Retrier) updateRetriesMap(retries map[string]int, actions []fleetapi.Action, resp *fleetapi.AckResponse) (failed []fleetapi.Action) {
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/reporter/fleet/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func (e *event) Message() string {

// Reporter is a reporter without any effects, serves just as a showcase for further implementations.
type Reporter struct {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct with 88 pointer bytes could be 56

lastAck time.Time
info agentInfo
logger *logger.Logger
queue []fleetapi.SerializableEvent
qlock sync.Mutex
threshold int
lastAck time.Time
qlock sync.Mutex
}

type agentInfo interface {
Expand Down