Skip to content

Conversation

@carlosms
Copy link
Contributor

This PR adds the advertized window support to the memory queue.

Context: this is needed in lookout, to handle memory or rabbitMQ queues with the same code. src-d/lookout#321.

For compatibility with other projects that may rely on the lack of window, I left the option to use 0 to disable it.

memory/memory.go Outdated
"sync"
"time"

"golang.org/x/sync/semaphore"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do the same with sync.WaitGroup

Copy link
Contributor

@erizocosmico erizocosmico Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And without it, you can just do with a channel.

n := 5 // number of workers // first fill the channel up to N workers var ch = make(chan struct{}, n) for i := 0; i < n; i++ { ch <- struct{}{} } // before starting a new worker, wait until there's a spot available <-ch // when the worker is finish, just generate a new token ch <- struct{}{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we could go with a channel. Do you think it's worth it to avoid using golang.org/x/?

@erizocosmico
Copy link
Contributor

erizocosmico commented Oct 16, 2018 via email

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
@carlosms
Copy link
Contributor Author

Ok I've redone the semaphore to be a channel.

Instead of following @erizocosmico's suggestion to the letter, I used send to acquire and receive to release, since that's how it's done in the effective go example

Copy link

@kuba-- kuba-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to add Ack() to queue.Job instead of having Acknowledger with references to JobIter members?

memory/memory.go Outdated
}

if advertisedWindow > 0 {
jobIter.sem = make(chan struct{}, advertisedWindow)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename it, to:

Suggested change
jobIter.sem = make(chan struct{}, advertisedWindow)
jobIter.chn = make(chan struct{}, advertisedWindow)

with sem it's super confusing now.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least chn tells me something about type. In go not so often you use semaphores, moreover without having semaphore type I don't know what to expect.
This is just a proposal - up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind one way or the other. Changed in e25f9e5.

@erizocosmico
Copy link
Contributor

erizocosmico commented Oct 16, 2018 via email

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
@carlosms
Copy link
Contributor Author

@kuba--

Does it make sense to add Ack() to queue.Job instead of having Acknowledger with references to JobIter members?

🤔 I don't really follow what you mean. The common queue.Job already has an Ack(), If we mess with it we'll probably break the amqp and other borges queues.

@kuba--
Copy link

kuba-- commented Oct 17, 2018

@carlosms - ok make sense. I was just confused, why JobIter also has a acquire/release mechanism

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants