独孤侠
独孤侠
My current solution is to reduce the time required for this HTTP request, but it feels terrible.
@ploxiln hello?
Hope to have this function as soon as possible. There's also a question, I have N * nsqd, 3 * lookup, and each nsqd will connect to each lookup, which...
> Sorry my English is not very good. I have a similar problem > > Polling query can be tolerated, but this can happen: > > A, B and C...
人家不需要例子,只是分享自己的代码。
但不关闭连接的时候,如果客户端不发消息了,不是会阻塞在Read这里吗?
感觉这个东西没有意义。
你写了一个比之前复杂的保证安全的逻辑,但仔细看,还是会有问题 ``` if atomic.CompareAndSwapInt32(&m.tryFlag, 0, 1) { atomic.StoreInt64(&m.cursor, 0) atomic.StoreInt32(&m.tryFlag, 0) m.synCond.Broadcast() } else { m.synCond.L.Lock() m.synCond.Wait() m.synCond.L.Unlock() } ``` 你不能保证你在m.synCond.Broadcast()时,所有其他协程都在m.synCond.Wait() 虽然你的逻辑也不能保证m.synCond.Broadcast()之前,只有一个协程进入if的then里,但如果只有一个进入了then而有2个进入了else其中一个到了Wait,还有一个在Lock()等待进入中 这个时候你的m.synCond.Broadcast()只能让之前在wait的出来,然后Lock()就进入了wait。 这个时候,如果没有新的协程去m.synCond.Broadcast(),那这个Wait就会一直wiat下去。 虽然Wait方法里面会在添加监听后,释放锁,让别的协程可以进来,但是依然存在着我上面说的那种情况发生的概率;
你把workers从数组改成了双map进行切换,但你写的并没有达到目标,只是map在获取的时候,可以检查而已,并不需要双map 如果使用双map那每次就应该只更新其中一个map,但那样的话就会导致资源的不释放问题,和你写这个东西的初衷就违背了。
还有一个问题,那就是你的双map是同一个map,导致一修改数量,就会出现 fatal error: concurrent map read and map write