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

Make Workers open and close a database connection #68

Open
adnseek opened this issue Jan 26, 2023 · 3 comments
Open

Make Workers open and close a database connection #68

adnseek opened this issue Jan 26, 2023 · 3 comments

Comments

@adnseek
Copy link

adnseek commented Jan 26, 2023

Hi Gammazero,

i'm using your great workerpool, and i have a problem. I use the submit() function to add jobs that are processed by the workers. But these workers need to perform database tasks. When i submit my worker function and put the db.Open and db.Close inside, i have too many connections.

My Question is now : is it possible to let the workers themselves open and close the connections, so that i always have the limited number of connections open. That would be awesome

Thanks in advance
Adrian

@adnseek
Copy link
Author

adnseek commented Jan 27, 2023

i changed my code now from .Submit() top .WaitSubmit(). Thats slower, but it somehow works.

Maybe you have an idea about my upper question nevertheless.

Adrian

@hut8
Copy link

hut8 commented Feb 26, 2023

Are you using the standard library's database/sql package? If so, you can just create one sql.DB and share it. It has its own pool of connections. The limit is set by https://pkg.go.dev/database/sql#DB.SetMaxOpenConns , which by default is unlimited. If it tries to make that many connections, something else is wrong. Posting your code would help.

See: https://go.dev/doc/database/manage-connections

@adnseek
Copy link
Author

adnseek commented May 13, 2023

hi @hut8 the solution was to put the sql.Open and Close to the start and the end of the job's function.

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

No branches or pull requests

2 participants