Too many connections issue
Opened this issue · 0 comments
I'm using SLIM Framework with Laravel's Eloquent ORM for REST APIs. Recently I faced a problem of too many connections.
During one request URI, I need to make several Get and Set calls to mySql DB. This opens connections on every DB transaction I make. I want to avoid that. Right now, mysql connection pool has 200 threads.
my API is expected to have more than 1000 concurrent calls and with the current environment, 40% of the calls will fail(tested using jMeter).
My idea is that for one API call, my application should use only one connection thread and increase the MySql connections pool to somewhere around 1000 to 1500 . is this a bad approach?
With Eloquent ORM, i have my DB connection being managed by Capsule. Should I make the first connection using Singleton method and for any subsequent call in API request, the same thread should be used?
Here is my database connection manager:
use Illuminate\Database\Capsule\Manager as Capsule;
/**
* Configure the database and boot Eloquent
*/
$capsule = new Capsule;
$capsule->addConnection($databaseConfig['mysql']);
// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$dispatcher = new Dispatcher(new Container);
$capsule->setEventDispatcher($dispatcher);
$capsule->setAsGlobal();
$capsule->bootEloquent();
What is the best approach to come out of this problem?