The current request time to SearchSerivce is too big (~300ms)
Need to optimize search request by removing/caching extra queries and
Repo: https://github.com/magento/storefront-search-ce
Service method: \Magento\SearchStorefront\Model\SearchService::searchProducts
With cached configuration we can expect only 3 requests to DB
- request to get synonyms: \Magento\SearchStorefrontSearch\Adapter\Query\Preprocessor\Synonyms::process
- request to get store/website data
- request to get attributes labels to build the response for layered navigation
All of them may be cached/optimized
Places to check:
- load Store in searchProducts method
- Optmize build query logic in Magento\SearchStorefrontElasticsearch\SearchAdapter\Query\Builder\Match::buildQueries
- there are a lot of SQL requests for eav attributes like "color", "description" ,which not present in the search request
To check SQL queries and trace to them we can enable db log in app/etc/env.php:
# to enable db logs add into env.php:
'db_logger' => [
'output' => 'file',
'log_everything' => 1,
'query_time_threshold' => '0',
'include_stacktrace' => 1
]
To test search without gRPC request:
<?php
use Magento\SearchStorefrontApi\Api\Data\ProductSearchRequest;
use Magento\SearchStorefrontApi\Api\Data\ProductSearchRequestMapper;
try {
require __DIR__ . '/app/bootstrap.php';
} catch (\Exception $e) {
exit(1);
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$om = $bootstrap->getObjectManager();
/** @var ProductSearchRequestMapper $requestMapper */
$requestMapper = $om->create(ProductSearchRequestMapper::class);
$requestArray = [
'phrase' => 'simple',
'store' => '1',
'include_aggregations' => false,
'customer_group_id' => 0,
'page_size' => 5,
'filters' => [
// [
// 'attribute' => 'color',
// 'eq' => 98
// ],
// [
// 'attribute' => 'material',
// 'in' => ['199','195']
// ],
[
'attribute' => 'price',
'range' => [
'from' => 0,
'to' => 30
]
]
]
];
$request = $requestMapper->setData($requestArray)->build();
/** @var Magento\SearchStorefront\Model\SearchService $searchService */
$searchService = $om->get(\Magento\SearchStorefront\Model\SearchService::class);
$res = $searchService->searchProducts($request);
print_r($res->getItems());
print_r($res->getFacets());
print('Items: ' . count($res->getItems()) . ', Facets: '.count($res->getFacets()));
//echo "\n time:", (\microtime(true) - $t), "\n";
The current request time to SearchSerivce is too big (~300ms)
Need to optimize search request by removing/caching extra queries and
Repo: https://github.com/magento/storefront-search-ce
Service method: \Magento\SearchStorefront\Model\SearchService::searchProducts
With cached configuration we can expect only 3 requests to DB
All of them may be cached/optimized
Places to check:
To check SQL queries and trace to them we can enable db log in app/etc/env.php:
To test search without gRPC request: