Reduce using mutex when update application settings. #329

Open
opened 2024-03-04 08:41:25 +00:00 by dkirillov · 0 comments
Collaborator

We have appSettings.update method that fetch and update config params. Each function inside appSettings.update acquire lock that in general ok, but we can reduce amount of lock/unlock operations during sighup reload.

Describe the solution you'd like

Use just one lock/unlock operation during sighup. So we can change the appSettings.update method to look like appSettings.updateNamespacesSettings:

func (s *appSettings) update(v *viper.Viper, log *zap.Logger, key *keys.PrivateKey) {
    nsHeader := v.GetString(cfgResolveNamespaceHeader)
	nsConfig, defaultNamespaces := fetchNamespacesConfig(log, v)
    // configuring other params
    // ... 

	s.mu.Lock()
	defer s.mu.Unlock()

	s.namespaceHeader = nsHeader
	s.defaultNamespaces = defaultNamespaces
	s.namespaces = nsConfig.Namespaces
    // set other params
    // ...
}

Describe alternatives you've considered

Don't change anything

Additional context

No

## Is your feature request related to a problem? Please describe. We have [appSettings.update](https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/src/commit/8050ca2d517ebfd64e33764c137f86b703611146/cmd/s3-gw/app.go#L223) method that fetch and update config params. Each function inside `appSettings.update` acquire lock that in general ok, but we can reduce amount of lock/unlock operations during sighup reload. ## Describe the solution you'd like Use just one lock/unlock operation during sighup. So we can change the `appSettings.update` method to look like `appSettings.updateNamespacesSettings`: ```golang func (s *appSettings) update(v *viper.Viper, log *zap.Logger, key *keys.PrivateKey) { nsHeader := v.GetString(cfgResolveNamespaceHeader) nsConfig, defaultNamespaces := fetchNamespacesConfig(log, v) // configuring other params // ... s.mu.Lock() defer s.mu.Unlock() s.namespaceHeader = nsHeader s.defaultNamespaces = defaultNamespaces s.namespaces = nsConfig.Namespaces // set other params // ... } ``` ## Describe alternatives you've considered Don't change anything ## Additional context No
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-s3-gw#329
There is no content yet.