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

Is it possible to run the tasks one after the other? #325

Closed
alandecastros opened this issue Mar 2, 2023 · 2 comments
Closed

Is it possible to run the tasks one after the other? #325

alandecastros opened this issue Mar 2, 2023 · 2 comments

Comments

@alandecastros
Copy link
Contributor

In this code you're runnning WhenAll making the tasks run in parallel, right?

await Task.WhenAll(

I'm running into some issues with database max pool size limit (lots of tasks running at the same time) and wanted to know what you think about creating an option to run tasks one by one? Or am I missing something?

Regards

@jamesmh
Copy link
Owner

jamesmh commented Mar 2, 2023

Yes, that's an issue that can come up. This used to be the way Coravel worked, but changed it for throughput reasons. I not sure adding this as an option should be a concern of Coravel proper....

There are other ways around this specific issue.

1

You create a static (or DI injected) class that handles creating all your DB connections. This will pool or just limit how many connections can be used at a given time.

Different interfaces could exist for something like this:

var sqlConnection = await connectionPool.GetOpenConnectionAsync();

Or

await connectionPool.WithSqlConnection(async sqlConnection => {
    await sqlConnetion.ExecuteAsync(SQLString_const);
});

Under the covers, you would probably use a semaphore to limit how many actions can occur concurrently.

2

Another consideration: it might be that your code could be issuing too many SQL connections and that could be optimized.

3

Or, if your code gets a specific exception, you could handle that specific exception and retry in X milliseconds (with backoff, etc.) Many use something like Poly for that.

4

Or, it could be a legit issue where there's some bad code that's not releasing DB connections efficiently. Here's a SO example: https://stackoverflow.com/questions/49748789/max-connection-pool-reached

@alandecastros
Copy link
Contributor Author

Thanks @jamesmh ! I'll see my options here!

Regards

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