orchestral / tenanti

[Package] Multi-tenant Database Schema Manager for Laravel
MIT License
587 stars 53 forks source link

Too Many Connections #58

Closed ghost closed 6 years ago

ghost commented 7 years ago

I'm trying to migrate to 1500+ database by this command php artisan tenanti:migrate

but all the connection still opened and make usage of ram very high

and the connections is more than 1500+ and still opened.

I want after each migration database the connection is closed

crynobone commented 7 years ago

Feel free to send a Pull Request.

ghost commented 7 years ago

Thanks @crynobone , I don't have idea how can solve this .

I think after each migration (tenant) must to close the connection

I wander if I have more than 10000 databases , so I need to make the max connection to 100000 to make the migration works find?

crynobone commented 7 years ago

There php artisan tenanti:queue migrate large projects. Personally I'm using this on a single database connection therefore would really welcome contribution for multi-database setup.

ghost commented 7 years ago

Thanks @crynobone , I will try to fix this problem and I will share it with you if I found solution , and I hope any one can help us, I will be very thankful.

I make this steps: I have 1500 databases and make max connection in mysql is 2000 connections 1- run (php artisan tenanti:queue tenant migrate ) . 2- run (php artisan queue:work) and now it will take first 538 tenants to migrate it. Then this error showing in bugsnage. Illuminate\Database\QueryException · SQLSTATE[HY000]: General error: 1016 Can't open file: './dhmdb_579/tenant_579_migrations.frm' (errno: 24 - Too many open files) (SQL: select migration from tenant_579_migrations order by batch asc, migration asc) when I go to mysql workbench or list proccess I found 583 connection still works and the migration is done.

so , just need to close connection after each migration

this is my migration file


 Schema::create("test".$id, function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });
crynobone commented 7 years ago

Are you on 3.5 or 3.4?

ghost commented 7 years ago

Laravel 5.4 Tenanti 3.4

ghost commented 7 years ago

hi , these are some screen shots

when I run php artisan tenanti:migrate ( more than 150+ connections are opened) imageedit_4_7153321951

rsz_screenshot_ _

when I update max_connections mysql server to 2000 connections rsz_screenshot_ _

I'm trying to close the connections after migrate each tenant but I cannot .

this package is working fine for one single database , because it need one connection and the connection will closed after finishing all migration files.

so I hope to make it close automatically after each migrate tenant

thanks @crynobone

h2akim commented 7 years ago

Is this issue related to this?

https://github.com/laravel/framework/issues/5311 ?

crynobone commented 7 years ago

Not related.

ghost commented 7 years ago

I upgraded my Laravel to 5.5 and package to 3.5 , and this is not solving the problem , I hope to update the package to fixed this issues

joys014 commented 7 years ago

If you cannot work around with the package then you can look at increasing max_connections in the my.cnf on your server. Reduce the number of max_connections after migration. Dont forget to restart mysql service, after every config change

drbyte commented 6 years ago

It feels like it's not actually firing the disconnect for the selected db connection. And therefore I wonder if the issue is in the logic of checking for "default connection is not null" when needing to reset the "connection" (not the default)?

See: https://github.com/orchestral/tenanti/blob/3.5/src/Migrator/Migrator.php#L62-L63

crynobone commented 6 years ago

therefore I wonder if the issue is in the logic of checking for "default connection is not null" when needing to reset the "connection" (not the default)?

The changes was made after this issue was created.

drbyte commented 6 years ago

Okay. Curious why this issue is still open then. :)

joel19 commented 6 years ago

@crynobone have you an example with eloquent into controllers(how get, store and update records) and models(how access to table with prefix records) in a project with single database ? , I don´t find documentation about this, thanks

muralibobby35 commented 5 years ago

We are using Laravel 5.4,Tenanti 3.4 We are getting the same issue. Please let us know is it possible to fix?