Reduce using mutex when update application settings. #329

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

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
r.loginov self-assigned this 2024-08-16 10:33:37 +00:00
alexvanin added this to the v0.31.0 milestone 2024-11-20 11:57:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
No description provided.