mysql optimization/clarification
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
I have done a quick test.
In blade view I added this code:
And modified a bit /vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Base/Locale.php:
The output is:
382
742
836
879
922
965
1008
1051
1094
1137
1180
Means the Aimeos\Shop\Base\Locale is always different object.. This is why $this->locale === null is always true .. (
Do you have ideas ?
In blade view I added this code:
Code: Select all
for($i = 0; $i < 10; $i++) {
aitrans('April');
}
Code: Select all
public function get( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Locale\Item\Iface
{
if( $this->locale === null )
{
$site = Request::input( 'site', 'default' );
$lang = Request::input( 'locale', app()->getLocale() );
$currency = Request::input( 'currency', '' );
if( Route::current() )
{
$site = Request::route( 'site', $site );
$lang = Request::route( 'locale', $lang );
$currency = Request::route( 'currency', $currency );
}
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$disableSites = $this->config->get( 'shop.disableSites', true );
$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites );
dump(spl_object_id($this));
}
return $this->locale;
}
The output is:
382
742
836
879
922
965
1008
1051
1094
1137
1180
Means the Aimeos\Shop\Base\Locale is always different object.. This is why $this->locale === null is always true .. (
Do you have ideas ?
Re: mysql optimization/clarification
It seems like the singleton method isn't only executed once but each time a context is requested:
https://github.com/aimeos/aimeos-larave ... hp#L84-L86
https://github.com/aimeos/aimeos-larave ... hp#L84-L86
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
Hi )
The above code makes the error. It get extra connection for each call.
I checked like you suggested if I understand you right like this:
And it printed only once. So I think it is called only once.
Again in /vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Base/Locale.php:
it printed as much as I called $context->get(); in loop. And id is different, so it is always different object.. (
Could not you try to reproduce it please ?
Code: Select all
for($i = 0; $i < 100; $i++) {
/** @var \Aimeos\Shop\Base\Context $context */
$context = app( '\Aimeos\Shop\Base\Context' );
$context->get();
}
I checked like you suggested if I understand you right like this:
Code: Select all
$this->app->singleton( 'aimeos.locale', function( $app ) {
dump(234);
return new \Aimeos\Shop\Base\Locale( $app['config'] );
});
$this->app->singleton( 'aimeos.context', function( $app ) {
dump(234);
return new \Aimeos\Shop\Base\Context( $app['session.store'], $app['aimeos.config'], $app['aimeos.locale'],
$app['aimeos.i18n'] );
});
Again in /vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Base/Locale.php:
Code: Select all
public function get( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Locale\Item\Iface
{
dump(spl_object_id($this));
....
}
Could not you try to reproduce it please ?
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
But I think the biggest problem even with project with oldest aimeos project...
I just recorded general mysql log for one request in BE dashboard. Of course I have cleared log before and just one time opened dashboard in browser.. A lot of queries and connections ( 150 connections just to visit BE dashboard..
All custom code I have removed before test..
max_user_connections = 40, user connections error was not appeared.. but lot connections and queries, I think so.. Where is a problem ? And also I noticed a lot ajax request you can see on screenshot.
here is full mysql general log https://temp.pm/?jX5Ah9dbYdYNa3pibWoQD7 ... lu0tjOwT-N
Is it really aimeos is so expensive for mysql ? I would be really pity about that Or what might be wrong ?
components versions are:
I hope very much we can figure it out. Thank you !
I just recorded general mysql log for one request in BE dashboard. Of course I have cleared log before and just one time opened dashboard in browser.. A lot of queries and connections ( 150 connections just to visit BE dashboard..
All custom code I have removed before test..
max_user_connections = 40, user connections error was not appeared.. but lot connections and queries, I think so.. Where is a problem ? And also I noticed a lot ajax request you can see on screenshot.
here is full mysql general log https://temp.pm/?jX5Ah9dbYdYNa3pibWoQD7 ... lu0tjOwT-N
Is it really aimeos is so expensive for mysql ? I would be really pity about that Or what might be wrong ?
components versions are:
Code: Select all
aimeos/ai-admin-jqadm 2019.10.6 Aimeos ai-admin-jqadm extension
aimeos/ai-admin-jsonadm 2019.10.2 Aimeos ai-admin-jsonadm extension
aimeos/ai-client-html 2019.10.10 Aimeos ai-client-html extension
aimeos/ai-client-jsonapi 2019.10.2 Aimeos JSON API extension
aimeos/ai-controller-frontend 2019.10.3 Aimeos ai-controller-frontend extension
aimeos/ai-controller-jobs 2019.10.4 Aimeos ai-controller-jobs extension
aimeos/ai-gettext 2019.10.1 Aimeos Gettext extension
aimeos/ai-laravel 2019.10.2 Laravel adapter for Aimeos web shops and e-commerce solutions
aimeos/ai-payments 2019.10.1 Payment extension for Aimeos web shops and e-commerce solutions
aimeos/ai-swiftmailer 2019.10.1 SwiftMailer adapter for Aimeos web shops and e-commerce solutions
aimeos/aimeos-core 2019.10.7 Full-featured e-commerce components for high performance online shops
aimeos/aimeos-laravel 2019.10.1 Professional, full-featured and high performance Laravel e-commerce package for online shops and complex B2B projects
- Attachments
-
- Screenshot from 2021-05-16 13-39-52.png (229.84 KiB) Viewed 7647 times
Re: mysql optimization/clarification
Why is the Locale object always different if these singletons are only called once?
The Locale object injected into the context is stored once and used several times:
- https://github.com/aimeos/aimeos-larave ... xt.php#L63
- https://github.com/aimeos/aimeos-larave ... t.php#L102
Code: Select all
$this->app->singleton( 'aimeos.locale', function( $app ) {
dump(234);
return new \Aimeos\Shop\Base\Locale( $app['config'] );
});
$this->app->singleton( 'aimeos.context', function( $app ) {
dump(234);
return new \Aimeos\Shop\Base\Context( $app['session.store'], $app['aimeos.config'], $app['aimeos.locale'],
$app['aimeos.i18n'] );
});
- https://github.com/aimeos/aimeos-larave ... xt.php#L63
- https://github.com/aimeos/aimeos-larave ... t.php#L102
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
Honestly I don't know, but I tried the below code in blade view and in search() method of dashboard Standard:
The output is:
1370
1411
1427
spl_object_id is different. Does it mean the objects are different right ? I think it must be the same object.. Why it happens I don't know really, I thought we could find out it together faster.. Is not it the same behavior on your side ?
Here is also different ids:
Code: Select all
dump(spl_object_id(app( '\Aimeos\Shop\Base\Context' )->get()));
dump(spl_object_id(app( '\Aimeos\Shop\Base\Context' )->get()));
dump(spl_object_id(app( '\Aimeos\Shop\Base\Context' )->get()));
1370
1411
1427
spl_object_id is different. Does it mean the objects are different right ? I think it must be the same object.. Why it happens I don't know really, I thought we could find out it together faster.. Is not it the same behavior on your side ?
Here is also different ids:
Code: Select all
/** @var \Aimeos\Shop\Base\Context $c */
$c = app( '\Aimeos\Shop\Base\Context' );
$a = app( '\Aimeos\Shop\Base\Context' );
dump(spl_object_id($a));
dd(spl_object_id($c));
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
Should this call always return the same object app( '\Aimeos\Shop\Base\Context' ) ?
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
aitrans() function consists app( '\Aimeos\Shop\Base\Context' )
this call app( '\Aimeos\Shop\Base\Context' ) - seems doesn't trigger singleton and as result it returns always new object, and therefor context inside itself performs extra mysql queries..
But if I use it so: app( 'aimeos.context' ) - then the same object is always returned.
Am I wrong ? What will you say ?
this call app( '\Aimeos\Shop\Base\Context' ) - seems doesn't trigger singleton and as result it returns always new object, and therefor context inside itself performs extra mysql queries..
But if I use it so: app( 'aimeos.context' ) - then the same object is always returned.
Am I wrong ? What will you say ?
Re: mysql optimization/clarification
Thanks for tracking this down. It's now changed to "aimeos.context" and available in dev-master, 2021.04.x-dev, 2020.10.x-dev and 2019.10.x-devMikaelNazarenko wrote: ↑18 May 2021, 10:35 aitrans() function consists app( '\Aimeos\Shop\Base\Context' )
this call app( '\Aimeos\Shop\Base\Context' ) - seems doesn't trigger singleton and as result it returns always new object, and therefor context inside itself performs extra mysql queries..
But if I use it so: app( 'aimeos.context' ) - then the same object is always returned.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: mysql optimization/clarification
No problem, I am glad to cooperate!
these are my packages versions:
Please, give me a tip, how do I grab the updates for 2021.04.2 but I want to leave 2021.04.2 and do not get it updated to higher ?
Thanks a lot !
these are my packages versions:
Code: Select all
aimeos/ai-admin-jqadm 2021.04.6 Aimeos Vue.js+Bootstrap admin interface
aimeos/ai-admin-jsonadm 2021.04.1 Aimeos ai-admin-jsonadm extension
aimeos/ai-client-html 2021.04.7 Aimeos ai-client-html extension
aimeos/ai-client-jsonapi 2021.04.1 Aimeos JSON API extension
aimeos/ai-cms-grapesjs 2021.04.2 Aimeos GrapesJS CMS extension
aimeos/ai-controller-frontend 2021.04.1 Aimeos ai-controller-frontend extension
aimeos/ai-controller-jobs 2021.04.3 Aimeos ai-controller-jobs extension
aimeos/ai-gettext 2021.04.1 Aimeos Gettext extension
aimeos/ai-laravel 2021.04.3 Laravel adapter for Aimeos web shops and e-commerce solutions
aimeos/ai-swiftmailer 2021.04.1 SwiftMailer adapter for Aimeos web shops and e-commerce solutions
aimeos/aimeos-core 2021.04.3 Full-featured e-commerce components for high performance online shops
aimeos/aimeos-laravel 2021.04.2 Professional, full-featured and high performance Laravel e-commerce package for online shops and complex B2B projects
Thanks a lot !