Dear Gophers,
I am working on a small database tool which checks a database for
inconsistencies. It does that by calling a stored procedure via sql.
Unfortunately the database client is available as C-library only but
luckily there is a go driver for the database/sql package so at least it
feels like pure go. Of course it is not as it uses cgo under the hood.
After all I got the basics working based on the following:
1. a producer goroutine reads from the database, creates the sql
statements to be run and passes them into a task channel
2. eight worker goroutines read from the task channel, run one task at a
time on the database and pass the result to a results channel (resChan)
3. main reads the results from the results channel
So far, so good. Then I wanted to add some progress info. As I know the
number of checks I added another channel (donChan). Each worker goroutine
sends an empty struct on that channel after a check has been finished. main
reads from that channel and decreases the remaining number of checks.
In the end I have something like this:
amount := 42
remaining := amount
for remaining > 0 {
select {
case <-time.After(5 * time.Second):
fmt.Printf("Progress: %d left from %d\n", remaining, amount)
case <-donChan:
remaining--
case res := <-resChan:
fmt.Println(res)
}
}
This is simplified but I hope you get the idea.
The effect is that as long as the eight worker and the producer goroutines
are running and using the database, I don't see the progress message which
should be triggered by time.After. To me it looks like the runtime is busy
with the large cgo threads and cannot handle/schedule the time.After
goroutine. But when I raise variable amount for testing while the number of
actual checks is lower (then the for look will run forever) I see the
Progress output as soon as the worker and the producer goroutines are done.
So the time.After is not dead - it's just blocked while cgo is used.
And here I would like to ask you for tips and help. If you have an idea and
you need more details please let me know.
I also came across Dave Cheneys
post https://dave.cheney.net/2016/01/18/cgo-is-not-go and I believe this is
what I am suffering from. Unfortunately there is no other database client
available. It is about SAPs database HANA and I know there is a pure go
implementation. Unfortunately this one lacks hdbuserstore support which is
some kind of password store for HANA I need. So I have to use the official
HANA client based on the C-library.
thanks for any help!
Chris
PS: I am using go 1.10.2 and also tried 1.10 with the same result
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.