承接 webandco/neos-asset-usage-cache 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webandco/neos-asset-usage-cache

Composer 安装命令:

composer require webandco/neos-asset-usage-cache

包简介

Improve asset usage query performance

README 文档

README

The package provides a strategy to cache the asset usage results. Additionally, the database query to fetch the related nodes is simplified and can be cached by the database server too.

Installation

Install the package with composer. It is recommended to use the package only in development environments.

composer require webandco/neos-asset-usage-cache

Features

This package provides various features to improve performance of querying the asset usage.

The alternative package https://github.com/punktDe/elastic-assetusageinnodes also solves the performance problem using an elasticsearch index. The main differences to the elasticsearch package are:

  1. This package, webandco/neos-asset-usage-cache, only needs the database you use for NEOS. There is no need for elasticsearch.
  2. We assume the cache to be more short-lived, whereas the elasticsearch package is basically an index of the nodes and updated accordingly.
  3. We also use a different method to inject our own AssetUsageStrategy. Via the Settings.yaml you can then disable/enable Strategies as you like. Thus you are more maneuverable and create add/extend your own AssetUsageStrategy - which is currently more complicated by default in NEOS.
  4. You can disable the cache completely in Settings.yaml if you want and just enable it on purpose, e.g. in a long running command controller of yours.
  5. You can also disable the cache itself and just let the database cache the results. This basically means that the query to determine the asset usage is modified. This approach can be very fast and provides correct results all the time. The drawback is that you need to reconfigure your database to increase query caches which can cause decreased query performance because of internal DB locks. More details and links down below.

Configurable asset usage strategy

Currently the asset usage is generated by iterating over all classes implementing the Neos\Media\Domain\Strategy\AssetUsageStrategyInterface and sum up or merge the results from the implementations.

In a default setup, it is not possible to enable/disable strategies, making it more complicated to replace the current default strategy Neos\Neos\Domain\Strategy\AssetUsageInNodePropertiesStrategy

This package uses an aspect for Neos\Media\Domain\Service\AssetService->getUsageStrategies() and the configuration to disable or enable strategies. Thus one can easier add or remove an AssetUsageStrategy.

Simplified database query

The default asset usage query in AssetUsageInNodePropertiesStrategy adds multiple LIKE conditions for the properties column to query the nodeData table.

The more an asset is in use, the more image variants exist, the more LIKE conditions are added and this slows the query down.

In this package we implemented an alternative approach, by just querying all rows which contain __identifier or asset: and then filter the results using PHP's preg_match_all. So the workload is moved away from the database and into PHP.

To make use of database query caching you likely need to increase query cache sizes, e.g.

SET GLOBAL query_cache_size = 500*1024*1024;
SET GLOBAL query_cache_limit = 200*1024*1024;

Keep in mind, that by increasing the database cache sizes, the database can actually be slowed down, see https://dev.mysql.com/doc/refman/5.6/en/query-cache.html:

Be cautious about sizing the query cache excessively large,
which increases the overhead required to maintain the cache,
possibly beyond the benefit of enabling it.
Sizes in tens of megabytes are usually beneficial.
Sizes in the hundreds of megabytes might not be. 

For futher details, see: https://haydenjames.io/mysql-query-cache-size-performance/

If you increase database query cache sizes, the query used in this package is cached, and there is no need for php caching.

Cached asset usage

The database result is managed via a cache, which is updated on signals for node changes and by default flushed every hour.

Performance

The database query used in this package, takes around 4 sec for for around 300.000 nodes in the nodeData table. The more nodes the slower this query becomes.

This database query is independent of any given asset or usage count and performs the same for every asset.

If the cache is populated, the methods provided by AssetUsageCacheStrategy take around 6ms per asset nearly independent of the usage count.

Configuration

The default configuration, disables the AssetUsageInNodePropertiesStrategy and enables the provided AssetUsageCacheStrategy.

Additionally the queryCache is enabled and realTimeUpdate is enabled.

Webandco:
  AssetUsageCache:
    assetUsageStrategies:
      AssetUsageInNodePropertiesStrategy:
        className: 'Neos\Neos\Domain\Strategy\AssetUsageInNodePropertiesStrategy'
        disable: true
      AssetUsageCacheStrategy:
        className: 'Webandco\AssetUsageCache\Domain\Strategy\AssetUsageCacheStrategy'
        disable: false
    queryCache:
      disable: false
      realTimeUpdate: true

Use cases

Database query cache only

To make use of the database query cache but not using the PHP cache, just disable the cache in the configuration

Webandco:
  AssetUsageCache:
    queryCache:
      disable: true

Enable cache on purpose

In case the cache should be not used in the media browser, but during a custom command line action, the cache needs to be disabled via configuration, see above.

In the command line action you can then enable the cache


    /**
     * @Flow\Inject
     * @var AssetCacheService
     */
    protected $assetCacheService;

....

    public function reConfigureAssetCache(){
        $this->assetCacheService->setRealTimeUpdate(false);
        $this->assetCacheService->setCacheDisabled(false);
        // eventually just flush the cache - globally
        $this->assetCacheService->flush();
    }

Thus the cache is used during the run of the current command line action which can be handy if you need to iterate over all assets and check their usage count.

webandco/neos-asset-usage-cache 适用场景与选型建议

webandco/neos-asset-usage-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.45k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 11 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 webandco/neos-asset-usage-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webandco/neos-asset-usage-cache 我们能提供哪些服务?
定制开发 / 二次开发

基于 webandco/neos-asset-usage-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-11-06