소스 검색

dont close the channel when we're done, avoids lock congestion

backfeed-full-error
Fusl 2 년 전
부모
커밋
d14917c95d
1개의 변경된 파일17개의 추가작업 그리고 16개의 파일을 삭제
  1. +17
    -16
      main.go

+ 17
- 16
main.go 파일 보기

@@ -54,7 +54,7 @@ type ProjectBackfeedManager struct {
BackfeedRedis *redis.ClusterClient BackfeedRedis *redis.ClusterClient
ProjectRedis *redis.Client ProjectRedis *redis.Client
LegacyRedis *redis.Client LegacyRedis *redis.Client
Lock sync.RWMutex
//Lock sync.RWMutex
ProjectConfig ProjectConfig ProjectConfig ProjectConfig
} }


@@ -66,11 +66,11 @@ func (that *ProjectBackfeedManager) RedisConfigDiffers(new *ProjectRedisConfig)
} }


func (that *ProjectBackfeedManager) PushItem(ctx context.Context, item *BackfeedItem) bool { func (that *ProjectBackfeedManager) PushItem(ctx context.Context, item *BackfeedItem) bool {
that.Lock.RLock()
defer that.Lock.RUnlock()
if that.C == nil {
return false
}
//that.Lock.RLock()
//defer that.Lock.RUnlock()
//if that.C == nil {
// return false
//}
select { select {
case <-ctx.Done(): case <-ctx.Done():
return false return false
@@ -101,19 +101,20 @@ func (that *ProjectBackfeedManager) PopItem(blocking bool) (*BackfeedItem, bool)
} }
} }


func (that *ProjectBackfeedManager) CloseItemChannel() {
that.Lock.Lock()
defer that.Lock.Unlock()
if that.C == nil {
return
}
close(that.C)
that.C = nil
}
//func (that *ProjectBackfeedManager) CloseItemChannel() {
// log.Printf("closing item channel for %s", that.Name)
// that.Lock.Lock()
// defer that.Lock.Unlock()
// if that.C == nil {
// return
// }
// close(that.C)
// that.C = nil
//}


func (that *ProjectBackfeedManager) Do() { func (that *ProjectBackfeedManager) Do() {
defer close(that.Done) defer close(that.Done)
defer that.CloseItemChannel()
//defer that.CloseItemChannel()
defer that.Cancel() defer that.Cancel()


for { for {


불러오는 중...
취소
저장