Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vertexai(test): Run corpora test in go coroutine to reduce test runtime #10841

Merged
merged 20 commits into from
Sep 17, 2024

Conversation

happy-qiao
Copy link
Contributor

No description provided.

@happy-qiao happy-qiao requested review from a team as code owners September 10, 2024 16:46
@happy-qiao happy-qiao changed the title Run corpora test in go coroutine to reduce test runtime vertexai(test): Run corpora test in go coroutine to reduce test runtime Sep 10, 2024
worker := func() {
for corpora := range corporaChan {
if ucr.shouldSkip(corpora.Name) {
fmt.Printf("Skipping file: %s\n", corpora.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt is not usually concurrency-safe (nothing bad will happen but output can get mixed up between goroutines).

Use log.Printf inside goroutines instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
doneChan <- true
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this code will work fine, but since your workers don't actually return any results, I recommend a slightly different pattern, using a WorkGroup.

This example shows how: https://gobyexample.com/waitgroups

Then you won't need the loop clearing the doneChan in the main goroutine; you'll just do a wait on the group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
log.Fatalf("Failed to decode bytes: %v", err)
}
workerCountChan := make(chan int, 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand what this channel is for -- can you please explain?

Copy link
Contributor Author

@happy-qiao happy-qiao Sep 16, 2024

Choose a reason for hiding this comment

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

I use this channel to manage up to 10 corpora run simultaneously, preventing them from all launching at once.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for clarifying.

In this case the naming or a comment should be used to make this clearer. Also, for channels like this it's customary to have them carry no information, e.g. chan struct{} -- this further clarifies that the contents of the channel have no meaning.

The channel can be named something like workLimiter or concurrencyLimiter, or if you prefer to keep your channel name, just add a comment explaining what it's for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks for helping me improve it!

@eliben eliben added the automerge Merge the pull request once unit tests and other checks pass. label Sep 17, 2024
@gcf-merge-on-green gcf-merge-on-green bot merged commit 4e3e3ec into googleapis:main Sep 17, 2024
5 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants