1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Tests for redis vs database performance

This commit is contained in:
David Bomba 2021-12-17 18:04:34 +11:00
parent 0f70298abf
commit cda41fbd46
9 changed files with 101 additions and 58 deletions

View File

@ -67,20 +67,13 @@ use Symfony\Component\Console\Input\InputOption;
*/
class CheckDb extends Command
{
/**
* @var string
*/
protected $signature = 'ninja:check-db';
/**
* @var string
*/
protected $description = 'Check MultiDB';
protected $log = '';
private $entities = [
Account::class,
Activity::class,

View File

@ -56,13 +56,9 @@ use stdClass;
class CreateSingleAccount extends Command
{
use MakesHash, GeneratesCounter;
/**
* @var string
*/
protected $description = 'Create Single Sample Account';
/**
* @var string
*/
protected $signature = 'ninja:create-single-account {gateway=all} {--database=db-ninja-01}';
protected $invoice_repo;
@ -71,18 +67,6 @@ class CreateSingleAccount extends Command
protected $gateway;
/**
* Create a new command instance.
*
* @param InvoiceRepository $invoice_repo
*/
public function __construct(InvoiceRepository $invoice_repo)
{
parent::__construct();
$this->invoice_repo = $invoice_repo;
}
/**
* Execute the console command.
*
@ -94,6 +78,11 @@ class CreateSingleAccount extends Command
if(config('ninja.is_docker'))
return;
if (!$this->confirm('Are you sure you want to inject dummy data?'))
return;
$this->invoice_repo = new InvoiceRepository();
MultiDB::setDb($this->option('database'));
$this->info(date('r').' Create Single Sample Account...');

View File

@ -59,18 +59,6 @@ class CreateTestData extends Command
protected $invoice_repo;
/**
* Create a new command instance.
*
* @param InvoiceRepository $invoice_repo
*/
public function __construct(InvoiceRepository $invoice_repo)
{
parent::__construct();
$this->invoice_repo = $invoice_repo;
}
/**
* Execute the console command.
*
@ -80,6 +68,11 @@ class CreateTestData extends Command
{
if(config('ninja.is_docker'))
return;
if (!$this->confirm('Are you sure you want to inject dummy data?'))
return;
$this->invoice_repo = new InvoiceRepository();
$this->info(date('r').' Running CreateTestData...');
$this->count = $this->argument('count');

View File

@ -53,28 +53,15 @@ class DemoMode extends Command
{
use MakesHash, GeneratesCounter;
protected $name = 'ninja:demo-mode';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ninja:demo-mode';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Setup demo mode';
protected $invoice_repo;
public function __construct(InvoiceRepository $invoice_repo)
public function __construct()
{
parent::__construct();
$this->invoice_repo = $invoice_repo;
}
/**
@ -89,6 +76,8 @@ class DemoMode extends Command
if(config('ninja.is_docker'))
return;
$this->invoice_repo = new InvoiceRepository();
$cached_tables = config('ninja.cached_tables');
foreach ($cached_tables as $name => $class) {

View File

@ -39,7 +39,7 @@ class ParallelCheckData extends Command
/**
* @var string
*/
protected $name = 'ninja:pcheck-data';
protected $signature = 'ninja:pcheck-data';
/**
* @var string

View File

@ -17,7 +17,6 @@ use Illuminate\Support\Facades\Artisan;
class PostUpdate extends Command
{
protected $name = 'ninja:post-update';
/**
* The name and signature of the console command.
*

View File

@ -80,10 +80,14 @@ class Kernel extends ConsoleKernel
/* Run hosted specific jobs */
if (Ninja::isHosted()) {
$schedule->job(new AdjustEmailQuota)->dailyAt('23:00')->withoutOverlapping();
$schedule->job(new AdjustEmailQuota)->dailyAt('23:30')->withoutOverlapping();
$schedule->job(new SendFailedEmails)->daily()->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-01')->daily()->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('00:05')->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-01')->daily('00:50')->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('00:55')->withoutOverlapping();
$schedule->command('ninja:s3-cleanup')->dailyAt('23:15')->withoutOverlapping();
}
@ -91,6 +95,7 @@ class Kernel extends ConsoleKernel
if(config('queue.default') == 'database' && Ninja::isSelfHost() && config('ninja.internal_queue_enabled') && !config('ninja.is_docker')) {
$schedule->command('queue:work')->everyMinute()->withoutOverlapping();
$schedule->command('queue:restart')->everyFiveMinutes()->withoutOverlapping();
}

View File

@ -48,7 +48,6 @@ class ApplyNumber extends AbstractService
break;
default:
// code...
break;
}

View File

@ -0,0 +1,76 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Unit;
use App\Models\Currency;
use App\Models\Invoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Cache;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class RedisVsDatabaseTest extends TestCase
{
public function setUp() :void
{
parent::setUp();
// $this->markTestSkipped('Skip test no company gateways installed');
}
public function testRedisSpeed()
{
$start = microtime(true);
$currencies = Cache::get('currencies');
$currency = $currencies->filter(function ($item) {
return $item->id == 17;
})->first();
$total_time = microtime(true) - $start;
$this->assertTrue(true);
// nlog($total_time);
//0.0012960433959961
}
public function testDbSpeed()
{
$start = microtime(true);
$currency = Currency::find(17);
$total_time = microtime(true) - $start;
$this->assertTrue(true);
// nlog($total_time);
// 0.006152868270874
}
}