Problem/Motivation

In #2800605: Warn/inform users when the hosting environment has a too low limit of APCU cache we did not consider that ByteSizeMarkup::create returns a translated string representation of the size.

Steps to reproduce

  1. Need to make sure that PHP compile with APCu support and APCu cache was enabled
  2. If site has only English language, needs to add another language, Russian or example.
  3. Needs to set non-English language to admin user and go to site Status Report

Proposed resolution

Force set English for ByteSizeMarkup::create function

Result

Before patch:

screenshot

After patch:

screenshot

Issue fork drupal-3142928

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Chi created an issue. See original summary.

chi’s picture

Title: Status report wrongly warns of APCu memory limit » Status report wrongly warns of APCu memory limit when admin language is not English
chi’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB
andypost’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative, +Needs tests
andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests +Needs manual testing

As no way to factor/mock this setting

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Needs steps to test

apolitsin’s picture

I still have this problem after applying the patch. on status report page `/admin/reports/status`
... Drupal can run with a 32 МБ APCu limit. However, a 32 MB APCu limit (the default) or above ...

* 33554312 = [$memory_info['seg_size'] (default php7.+ = value 32M)
* 33554432 = Bytes::toInt($apcu_recommended_size)
We need to add another `120 bytes` somewhere.

if ($memory_info['seg_size'] + 120 < Bytes::toInt($apcu_recommended_size)) {

it fixes the problem, but maybe the real reasons maybe should be found in `Bytes::toInt()`?

chi’s picture

Re #7. That's a different issue not related to localization.

keha3912’s picture

StatusFileSize
new22.39 KB

APCU Warning drupal 9.0.7
The problem is still not resolved
Drupal 9.0.7

chi’s picture

@keha3913 did you try the patch?

keha3912’s picture

@Chi, I tried it now - patch really works

$ composer update drupal/system
Gathering patches for root package.
Removing package drupal/core so that it can be re-installed and re-patched.
- Removing drupal/core (9.0.7)
Deleting web/core - deleted
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Installing drupal/core (9.0.7): Loading from cache
- Applying patches for drupal/core
https://www.drupal.org/files/issues/2020-05-26/apcu-memory-report-314292... (Status report wrongly warns of APCu memory limit when admin language is not English)

$ grep apcu_recommended core/modules/system/system.install
$apcu_recommended_size = '32 MB';
if ($memory_info['seg_size'] < Bytes::toInt($apcu_recommended_size)) {
'@apcu_default_size' => $apcu_recommended_size,

keha3912’s picture

Drupal 9.1.0 - patch doesn't work

$ composer update drupal/system
Gathering patches for root package.
Removing package drupal/core so that it can be re-installed and re-patched.
- Removing drupal/core (9.1.0)
Deleting web/core - deleted
Loading composer repositories with package information
Package "drupal/system" listed for update is not locked.
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Installing drupal/core (9.1.0): Extracting archive
- Applying patches for drupal/core
https://www.drupal.org/files/issues/2020-05-26/apcu-memory-report-314292... (Status report wrongly warns of APCu memory limit when admin language is not English)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-05-26/apcu-memory-report-314292...

Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Generating autoload files
42 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Scaffolding files for drupal/core:

[RuntimeException]
Could not delete /var/www/html/web/sites/default/default.services.yml:

update [--with WITH] [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-install] [--no-autoloader] [--no-scripts] [--no-suggest] [--no-progress] [-w|--with-dependencies] [-W|--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [
]...

Version: 9.0.x-dev » 9.1.x-dev

Drupal 9.0.10 was released on December 3, 2020 and is the final full bugfix release for the Drupal 9.0.x series. Drupal 9.0.x will not receive any further development aside from security fixes. Sites should update to Drupal 9.1.0 to continue receiving regular bugfixes.

Drupal-9-only bug reports should be targeted for the 9.1.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.2.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

neclimdul’s picture

Issue tags: +Novice

conflict was with #3142934: Replace \Drupal\Component\Utility\Bytes::toInt() with \Drupal\Component\Utility\Bytes::toNumber() due to return type which just changed the name of the bytes helper method. Resolving the conflict should be trivial.

Concept looks correct though, don't rely on parsing the translated bytes value.

mitrpaka made their first commit to this issue’s fork.

mitrpaka’s picture

Status: Needs work » Needs review
StatusFileSize
new1.02 KB

Updated patch file included for use with composer.

MR: https://git.drupalcode.org/project/drupal/-/merge_requests/670

batkor’s picture

Version: 9.1.x-dev » 9.2.x-dev
andypost’s picture

Version: 9.2.x-dev » 9.3.x-dev

It should be fixed in 9.3 first

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tsotoodeh’s picture

Hi everyone
Here is to report that the issue was detected with Drupal version 9.3.0. Here is the error:

Depending on your configuration, Drupal can run with a 32 MB APCu limit. However, a 32 MB APCu limit (the default) or above is recommended, especially if your site uses additional custom or contributed modules.

Seems that there is a localization issue since the error is not displayed in the default language. Thanks to the idea provided in #7 the issue was resolved. Hope the core development teams look into this issue and fix it at the core level.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rajandro’s picture

StatusFileSize
new56.88 KB

I have tried to reproduce this issue locally using 9.3.x, 9.4.x, and 9.5.x. For all the versions it's working as expected, i.e. when the apc.shm_size is less than 32MB it's showing the warnings and when it's greater than 32MB, there are no such warnings!
NOTE: I have tried using MAMP (apache+mysql) and tried Spanish and French Languages along with/without English.

rajandro’s picture

StatusFileSize
new24.26 KB
new56.88 KB

Attaching the screenshot for 64MB and 14M messages and warning.

Wiktor7’s picture

I solved my problem with this code:

core/modules/system/system.install

395 - $apcu_actual_size = format_size($memory_info['seg_size']);
395 + $apcu_actual_size = format_size($memory_info['seg_size'],'en');

Who can please make these changes in Drupal.

mdranove’s picture

StatusFileSize
new851 bytes

@wiktor7

Attached is a patch with the changes you suggested

neclimdul’s picture

The correct fix is already in the merge request. That change breaks localization.

ivnish’s picture

Patch from MR works (Drupal 9.4) but string number is incorrect for Drupal 9.4. Needs reroll?

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wiktor7’s picture

StatusFileSize
new840 bytes
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This will need tests to show the test.

Also was previously tagged for IS update.

Did not test the issue.

chi’s picture

This will need tests to show the test.

See note #5.

smustgrave’s picture

Issue tags: -Needs tests

Missed that.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Wiktor7’s picture

StatusFileSize
new838 bytes

Drupal 9.5.10

Wiktor7’s picture

StatusFileSize
new888 bytes

Drupal 10.2.0

alayham made their first commit to this issue’s fork.

alayham’s picture

Status: Needs work » Needs review

To see this issue on a multilingual site, the string @size MB must be localized.

My solution fixes the issue while respecting the user language, however, I think the best solution is to make the byte comparison work correctly when comparing two byte representations in two different languages, or to just compare the byte size as numbers, not as strings.

neclimdul’s picture

Status: Needs review » Needs work

@alayham Yeah, the suggestion all along has been to avoid any localization and compare number/byte sizes directly.

https://git.drupalcode.org/project/drupal/-/merge_requests/670/diffs#not...

This was only in needs work because it doesn't have tests which is still true.

Taran2L changed the visibility of the branch 3142928-status-report-wrongly-d10.2 to hidden.

Taran2L changed the visibility of the branch 3142928-status-report-wrongly-d10 to hidden.

Taran2L changed the visibility of the branch 11.x to hidden.

ivnish’s picture

I have same problem as #7

$apcu_actual_size = ByteSizeMarkup::create($memory_info['seg_size'], 'en');
doesn't help

if ($memory_info['seg_size'] < Bytes::toNumber($apcu_recommended_size))
doesn't help too

bolaghi’s picture

hi.
this patch work for me in drupal 10.2.7:
status-report-apcu-3142928.patch

go to /core/modules/system/
then edit system.install
in line 427 remove
$apcu_actual_size = ByteSizeMarkup::create($memory_info['seg_size']);
replace with
$apcu_actual_size = ByteSizeMarkup::create($memory_info['seg_size'], 'en');

catch’s picture

Status: Needs work » Needs review

Per #5 this isn't going to be testable in a useful way - we can't fake the apcu memory limit for system_requirements(). Also think this is a good example where the new policy on https://www.drupal.org/about/core/policies/core-change-policies/core-gat... should apply.

smustgrave’s picture

Status: Needs review » Needs work

Can the issue summary be updated with least proposed solution and before/after screenshots.

Also the 1 MR still visible is for 9.1.x and still a number of patches so not sure which is to be reviewed.

ivnish changed the visibility of the branch 3142928-status-report-wrongly to hidden.

ivnish’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update, -Novice
StatusFileSize
new33.99 KB
new20.3 KB
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Can the issue summary be updated to include steps to reproduce the problem and ultimately what the proposed solution is.

ivnish’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
smustgrave’s picture

btw that after screenshot is that the wrong item?

catch’s picture

Status: Needs review » Needs work

One comment on the MR.

ivnish’s picture

Status: Needs work » Needs review
ivnish’s picture

btw that after screenshot is that the wrong item?

smustgrave, after screenshot doesn't have wrong warning about cache size

hetal.solanki’s picture

catch’s picture

Latest change in the MR looks good, but probably needs one more round of manual testing?

krakenbite’s picture

Status: Needs review » Reviewed & tested by the community

I have the same problem. MR works for me

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 37d8ea5cb4 to 11.x and e1902fee88 to 11.0.x and eeca1aec09 to 10.4.x and 2664526bdb to 10.3.x. Thanks!

alexpott’s picture

  • alexpott committed 2664526b on 10.3.x
    Issue #3142928 by ivnish, neclimdul, Wiktor7, mitrpaka, Chi, keha3912,...

  • alexpott committed eeca1aec on 10.4.x
    Issue #3142928 by ivnish, neclimdul, Wiktor7, mitrpaka, Chi, keha3912,...

  • alexpott committed e1902fee on 11.0.x
    Issue #3142928 by ivnish, neclimdul, Wiktor7, mitrpaka, Chi, keha3912,...

  • alexpott committed 37d8ea5c on 11.x
    Issue #3142928 by ivnish, neclimdul, Wiktor7, mitrpaka, Chi, keha3912,...
andypost’s picture

Thanks you a lot!

neclimdul’s picture

Oh wow, this is an old one. Thanks!

nikit’s picture

Just for info:
If php.ini: apc.shm_size=32M

https://github.com/krakjoe/apcu/blob/v5.1.23/apc_sma.c#L565

info->seg_size = sma->size - (ALIGNWORD(sizeof(sma_header_t)) + ALIGNWORD(sizeof(block_t)) + ALIGNWORD(sizeof(block_t)));

seg_size = = 33554312b, not 33554432b (32M) - 120 bytes difference in my server.
so $apcu_recommended_size = '32 MB'; in system.install isn't exact value for comparing.

andypost’s picture

@Nikit nice details, thank you!

taran2l’s picture

this requires a follow-up, as now there is a warning with comparing 32 Mb to 32 MB (and the reason is described by @Nikit )

PHP APCu caching
Enabled (32 MB)
Depending on your configuration, Drupal can run with a 32 MB APCu limit. However, a 32 MB APCu limit (the default) or above is recommended, especially if your site uses additional custom or contributed modules.

catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.