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

Go: Add /db handler. #100

Merged
merged 1 commit into from
Apr 10, 2013
Merged

Go: Add /db handler. #100

merged 1 commit into from
Apr 10, 2013

Conversation

kardianos
Copy link
Contributor

Adds a DB handler to the go source. You may need to add another command:
go get -u .
in your scrip to get the mysql driver library.

@tarndt
Copy link
Contributor

tarndt commented Apr 7, 2013

Code LGTM

@bhauer
Copy link
Contributor

bhauer commented Apr 8, 2013

Thanks for this, @kardianos! We have wanted a db test for Go for a while but never managed to get it done. We'll work to get this tested and accepted as soon as possible.

@tarndt
Copy link
Contributor

tarndt commented Apr 8, 2013

@kardianos @bhauer

What about running the queries in parallel?

ww := make([]World, qnum)
var done sync.WaitGroup
done.Add(qnum)
for i := 0; i < qnum; i++ {
    go func(idx int) {
        defer done.Done()
        q.QueryRow(rand.Intn(DB_ROWS)+1).Scan(&ww[idx].Id, &ww[idx].RandomNumber)
    }(i)
}
done.Wait()

@kardianos
Copy link
Contributor Author

This doesn't actually speed things up.

The http handler is already called in parallel. I've got them coded
side by side with a flag to switch between parallel and sequential if
you want it. But either way, I think you would want to be slightly
smarter about spawning go-routines, with a http concurrency of X and a
DB concurrency of Y, you will spawn and collect X * Y short lived
go-routines. That's a lot of memory allocations, even if though
go-routine are small. There might be a smart way to speed things up
and make more run in parallel. In such trivial code and sql, I really
don't care about it personally.

On Mon, Apr 8, 2013 at 9:57 AM, Tylor Arndt [email protected] wrote:

@kardianos @bhauer

What about running the queries in parallel?

ww := make([]World, qnum)
var done sync.WaitGroup
done.Add(qnum)
for i := 0; i < qnum; i++ {
go func() {
defer done.Done()
q.QueryRow(rand.Intn(DB_ROWS)+1).Scan(&ww[i].Id,
&ww[i].RandomNumber)
}()
}
done.Wait()


Reply to this email directly or view it on GitHub.

@tarndt
Copy link
Contributor

tarndt commented Apr 8, 2013

@kardianos : Thanks, I wasn't really suggesting that the above would be actual code to use, but I wanted to check to see if you had tested it in a parallel fashion, and it sounds like you have. Thanks for being thorough.

Once this is committed, I'm going to play with it and see if I can manage to make it faster.

@kardianos
Copy link
Contributor Author

@tarndt If you want to make it faster, use the vitess driver directly.

@TechEmpower TechEmpower merged commit c7007b7 into TechEmpower:master Apr 10, 2013
@pfalls1
Copy link
Contributor

pfalls1 commented Apr 10, 2013

Thanks @kardianos! It's nice to finally have a database test for Go.

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.

5 participants