-
Notifications
You must be signed in to change notification settings - Fork 84
Use channel in messaging between goroutine in stead of zmq.REQ #168
Conversation
This will properly handle worker crash on init by timeout. And in case of all workers crash, the channeler will not crash. Just all RPC will timeout. Also add mutex lock to make the workerQueue goroutine safe.
Since it will throw to the end-user. Providing meaningful exception with user term is better.
timeout when running the test with the i hope these are helpful:
|
} | ||
heartbeatAt = time.Now().Add(HeartbeatInterval) | ||
} | ||
|
||
lb.workers.Purge() | ||
lb.workers.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should defer lb.workers.Unlock()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is within the for
control. And the defer
is bind to func closure scope. If we want to use defer
here. We need to create a large function scope. Which I don't prefer.
delete(lb.addressChan, address) | ||
respChan <- []byte{0} | ||
case <-lb.stop: | ||
break ChannelerLoop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think simply returns here
break ChannelerLoop | ||
} | ||
} | ||
lb.logger.Infof("zmq channler stopped %p!\n", lb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be defer lb.logger.Infof(...)
frames = append([][]byte{lb.workers.Next()}, frames...) | ||
lb.backend.SendMessage(frames) | ||
lb.logger.Debugf("zmq/broker: server => plugin: %#x, %s\n", frames[0], frames) | ||
backend.SendMessage(frames) | ||
case nil: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also quit the loop by checking the stop
channel here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. This switch case is only zmq socket. Not go chan. So we cannot consume the chan here.
timeout chan string | ||
workers workerQueue | ||
logger *logrus.Entry | ||
stop chan int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you still have fresh memory what this struct does, could you add some comments to the meaning of the struct members?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have still got time: there are two components to this broker: one is a broker and the other is the channeler. There are some struct members that are only used in one component but not the other, perhaps we could make the distinction more obvious by creating separate structs for these two components.
if you enable edits on the branch for the pull request, I could make assorted changes such as typos on the pull request on your behalf |
// workerQueue is not goroutine safe. To use it safely across goroutine. | ||
// Please use the Lock/Unlock interace before manupliate the queue item via | ||
// methods like Add/Tick/Purge. | ||
// Comsuming method Next is the only method will acquire the mutex lock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“Comsuming”?
The timeout is because Travis running the test with Setting |
Making another PR. |
This will resolve socket exhaust problem on high concurrency.
connects #160