mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-25 04:01:29 +02:00
[management] Refactor/management/updchannel (#3645)
* refactoring updatechannel - use read mutex for send update
This commit is contained in:
parent
b9f82e2f8a
commit
7839d2c169
@ -42,10 +42,10 @@ func (p *PeersUpdateManager) SendUpdate(ctx context.Context, peerID string, upda
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
var found, dropped bool
|
var found, dropped bool
|
||||||
|
|
||||||
p.channelsMux.Lock()
|
p.channelsMux.RLock()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
p.channelsMux.Unlock()
|
p.channelsMux.RUnlock()
|
||||||
if p.metrics != nil {
|
if p.metrics != nil {
|
||||||
p.metrics.UpdateChannelMetrics().CountSendUpdateDuration(time.Since(start), found, dropped)
|
p.metrics.UpdateChannelMetrics().CountSendUpdateDuration(time.Since(start), found, dropped)
|
||||||
}
|
}
|
||||||
@ -141,12 +141,12 @@ func (p *PeersUpdateManager) CloseChannel(ctx context.Context, peerID string) {
|
|||||||
func (p *PeersUpdateManager) GetAllConnectedPeers() map[string]struct{} {
|
func (p *PeersUpdateManager) GetAllConnectedPeers() map[string]struct{} {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
p.channelsMux.Lock()
|
p.channelsMux.RLock()
|
||||||
|
|
||||||
m := make(map[string]struct{})
|
m := make(map[string]struct{})
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
p.channelsMux.Unlock()
|
p.channelsMux.RUnlock()
|
||||||
if p.metrics != nil {
|
if p.metrics != nil {
|
||||||
p.metrics.UpdateChannelMetrics().CountGetAllConnectedPeersDuration(time.Since(start), len(m))
|
p.metrics.UpdateChannelMetrics().CountGetAllConnectedPeersDuration(time.Since(start), len(m))
|
||||||
}
|
}
|
||||||
@ -163,10 +163,10 @@ func (p *PeersUpdateManager) GetAllConnectedPeers() map[string]struct{} {
|
|||||||
func (p *PeersUpdateManager) HasChannel(peerID string) bool {
|
func (p *PeersUpdateManager) HasChannel(peerID string) bool {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
p.channelsMux.Lock()
|
p.channelsMux.RLock()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
p.channelsMux.Unlock()
|
p.channelsMux.RUnlock()
|
||||||
if p.metrics != nil {
|
if p.metrics != nil {
|
||||||
p.metrics.UpdateChannelMetrics().CountHasChannelDuration(time.Since(start))
|
p.metrics.UpdateChannelMetrics().CountHasChannelDuration(time.Since(start))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user