Comments (12)
Then my guess is that it's this:
It might be that in the example above, the connection is removed from Laravel's DatabaseManager but is actually still kept open on MySQL.
We'll look into it 👍🏻 @lukinovec could you try to reproduce this in a testing app?
from tenancy.
Currently problem is solved using queue:listen instead but the performance is better with queue:work command
What's the difference between those two in how the DB connections work?
The problem sounds like the DB connections don't get cleaned up, but $tenant->run()
should be properly cleaning up the old connection.
from tenancy.
Currently problem is solved using queue:listen instead but the performance is better with queue:work command
What's the difference between those two in how the DB connections work?
The problem sounds like the DB connections don't get cleaned up, but
$tenant->run()
should be properly cleaning up the old connection.
Hi,
Main difference between queue:listen
and queue:work
is that first one the framework is booted each job (closing connection also) while queue:work
framework is booted only one time, so it is much more efficient.
I believe that connection need to be closed by tenant run or manually but I am stuck.
from tenancy.
> isset(app('db')->getConnections()['tenant']);
= false
> $tenant->run(fn () => app('db')->getConnections()['tenant']);
= Illuminate\Database\MySqlConnection {#3828} // tenant connection exists inside the run() Closure
> isset(app('db')->getConnections()['tenant']);
= false // cleaned up afterwards
Could it be that you're using tenants:run
instead of $tenant->run()
? Could you show the exact code?
It might be that in the example above, the connection is removed from Laravel's DatabaseManager
but is actually still kept open on MySQL.
from tenancy.
Hi, I am using tenants:run
and database connection is open in MySQL (listing from SHOW FULL PROCESSLIST
)
Here you have an example:
Command class:
class MyCommand extends Command
{
/**
* {@inheritdoc}
* @var string
*/
protected $signature = 'myCompany:my-command';
/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
MyJob::dispatch();
}
}
Job class:
class MyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
logger()->info("running");
}
}
Steps to reproduce:
- php artisan queue:work --tries=3 --sleep=3 --daemon
- tenants:run myCompany:my-command
- Every time I run
tenants:run
, a new connection (per tenant) is open keeping previous one open forever
from tenancy.
What if you did:
Tenant::all()->runForEach(function () {
MyJob::dispatch();
});
and called myCompany:my-command
without tenants:run
.
Does that also reproduce the issue?
from tenancy.
Hi again,
Yes, following your advice produce same result
from tenancy.
FWIW regarding the solution, I'm not sure if this will be feasible:
Keep connections open by tenant and use it instead of create new one.
We may have to close the connections completely and then reopen them as needed.
from tenancy.
Yes maybe keep connections open is not feasible, close connects will be a good choise.
from tenancy.
@jacksnchz Can you try usingTenant Aware Commands?
I am not entirely sure it will work, but I was facing similar problem on my staging (PHP 8).
And this helped. further testing pending
from tenancy.
Hi @chinmaypurav,
Thank you for your help but the behaviour using TenantAwareCommand
is worst than original idea, more connections are kept open.
My temporary solution was replace queue:work
by queue:listen
command (loosing performance but it does not overloads the database connections).
from tenancy.
@jacksnchz This PR should fix the issue #1128
Could you try testing the change locally to see if it resolves the issue for you?
Essentially just open vendor/stancl/tenancy/src/Bootstrappers/QueueTenancyBootstrapper.php
and change line ~73 like this:
- if ($runningTests) {
+ if (true) {
to test the changes from the PR in a simpler way.
from tenancy.
Related Issues (20)
- Tenancy for Laravel considers www. as a tenant HOT 10
- Following valid tenant with a period will result in TenantCouldNotBeIdentifiedOnDomainException HOT 1
- Saving failed queues in the tenant database HOT 1
- Allow databases to be created independently of tenants HOT 11
- NovaServiceProvider - boot - access to tenancy HOT 2
- Call to a member function where() on string HOT 4
- How to deal with unregistered subdomains HOT 1
- domain query every requst HOT 1
- Generic model type "returned" by Tenant::all() raises a warning in Larastan/PHPstan HOT 1
- Supervisor fail with message "relation 'jobs' does not exist" HOT 1
- Tenant migrations add tables to the central db when using DATABASE_URL in the .env file HOT 4
- Call to undefined method Stancl\Tenancy\Database\Models\Tenant::domains() HOT 2
- Tenants not created using migrations HOT 1
- Livewire does not work for central domains when using Single Database Tenancy HOT 12
- Can i connect muti server DB ? HOT 1
- CORS issue with cached domains in a multi-tenant Laravel application HOT 1
- How can I make the registration of a CustomeServiceProvider conditional on the tenant? HOT 5
- url() method in notification class points to central app HOT 1
- Synced resources (both central and tenant), on creation, contain identical primary keys, even when incrementing ids is enabled. (Diagnosis included) HOT 3
- duplicate routes with Laravel 10 using breeze and sub domain not posting register to correct db HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tenancy.