Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

enable opcache #444

Closed
wants to merge 1 commit into from
Closed

enable opcache #444

wants to merge 1 commit into from

Conversation

kevinpapst
Copy link
Collaborator

@kevinpapst kevinpapst commented Jan 9, 2023

can someone please test these changes.
i don't know if that is even the correct file to change... 😁

while being on it, i changed the default session timeout from 14 minutes to 1 week.

the setting opcache.validate_timestamps might cause troubles for files changed during runtime (like updated invoice templates). we should mention in the docs, that a docker restart (actually fpm) is advised if file changes do not become visible in the container

do not merge without testing, these changes were made blindly!!!

can someone please test these changes.
i don't know if that is even the correct file to change... 😁 

while being on it, i changed the default session timeout from 14 minutes to 1 week.

the setting `opcache.validate_timestamps` might cause troubles for files changed during runtime (like updated invoice templates). 
we should mention in the docs, that a docker restart (actually fpm) is advised if file changes do not become visible in the container
@kevinpapst kevinpapst linked an issue Jan 9, 2023 that may be closed by this pull request
@kevinpapst kevinpapst marked this pull request as draft January 9, 2023 11:40
@kevinpapst kevinpapst added the enhancement New feature or request label Jan 9, 2023
@LiaraAlis
Copy link
Contributor

I'm not sure what I need to do to test these changes, but I assume that I have to do docker build and then running docker-compose up.
If this is so, this changes aren't working. I looked at the Dockerfile before and I think the changes @tobybatch mentioned in #438 is the way to go. I will try this later.

@kevinpapst
Copy link
Collaborator Author

but opcache is not an extension afaik, it is built in php.

no clue, not a docker user 🤷but what about you ssh into the container, edit the file manually and apply my changes, restart fpm inside the container and check if performance improves.

we first need to confirm whether the settings do any good - and then we can ask @tobybatch to put it into the image properly.

@tobybatch
Copy link
Owner

@kevinpapst I'll take a look.

@tobybatch
Copy link
Owner

Looks like the opcache settings are not set at all. I'll fix this. I'll do it in the next couple of days.

✘  ~/usr/kimai/kimai2 [ kevinpapst-patch-1 | ✔  ] $ docker run -ti --rm --name=kimai --entrypoint bash docker.io/kimai/kimai2:fpm-1.30.1-prod
bash-5.1$ php -i | grep "opcache.enable\|opcache.memory_consumption\|opcache.interned_strings_buffer\|opcache.max_accelerated_files\|opcache.validate_timestamps\|session.gc_maxlifetime"
session.gc_maxlifetime => 604800 => 604800

@LiaraAlis
Copy link
Contributor

LiaraAlis commented Jan 10, 2023

@kevinpapst No, it's an extension. If you compile PHP manually you can compile it directly, but as far as I know in apt packages it is a separate package.
I tried to change the Dockerfile and was able to confirm that this is working:

  1. Add the following code after this:
# php extension opcache
FROM ${BASE}-php-ext-base AS php-ext-opcache
RUN docker-php-ext-install -j$(nproc) opcache
  1. Add the following code after this:
COPY --from=php-ext-opcache /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini  /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini

image

As hoped, I could notice a strong increase in speed.

@kevinpapst
Copy link
Collaborator Author

Ok, double checked and you are right, opcache is an extension. It is even in the Kimai installation docs ... never trust your own memory ^^

Anyhow, great that we have everything together now. And great that this rather simple chance will make a huge difference.

@LiaraAlis LiaraAlis mentioned this pull request Jan 10, 2023
@LiaraAlis
Copy link
Contributor

Because I'm not able to change anything in this PR, I've created a new pr #446. I hope this is okay for you. 😊

@kevinpapst
Copy link
Collaborator Author

LOL, happy that my PR pushed you to try it yourself ;-) but I would like to understand the configuration of the opcode cache.

The default settings are suboptimal: too small for a symfony application with many files, caches and long uptimes.

Can you add a phpinfo to the kimai public folder and copy & paste the result of the opcode settings? Then this PR can be used to improve them after yours activated the opcode cache.

@LiaraAlis
Copy link
Contributor

LiaraAlis commented Jan 11, 2023

www-data@814fec82650f:/opt/kimai/public$ php -i | grep opcache                                                                                                                                              
/usr/local/etc/php/conf.d/docker-php-ext-opcache.ini,                                                                                                                                                       
opcache.blacklist_filename => no value => no value                                                                                                                                                          
opcache.consistency_checks => 0 => 0                                                                                                                                                                        
opcache.dups_fix => Off => Off                                                                                                                                                                              
opcache.enable => On => On                                                                                                                                                                                  
opcache.enable_cli => Off => Off                                                                                                                                                                            
opcache.enable_file_override => Off => Off                                                                                                                                                                  
opcache.error_log => no value => no value                                                                                                                                                                   
opcache.file_cache => no value => no value                                                                                                                                                                  
opcache.file_cache_consistency_checks => On => On                                                                                                                                                           
opcache.file_cache_only => Off => Off                                                                                                                                                                       
opcache.file_update_protection => 2 => 2                                                                                                                                                                    
opcache.force_restart_timeout => 180 => 180                                                                                                                                                                   
opcache.huge_code_pages => Off => Off                                                                                                                                                                       
opcache.interned_strings_buffer => 8 => 8                                                                                                                                                                   
opcache.jit => tracing => tracing                                                                                                                                                                           
opcache.jit_bisect_limit => 0 => 0                                                                                                                                                                          
opcache.jit_blacklist_root_trace => 16 => 16                                                                                                                                                                
opcache.jit_blacklist_side_trace => 8 => 8                                                                                                                                                                  
opcache.jit_buffer_size => 0 => 0                                                                                                                                                                           
opcache.jit_debug => 0 => 0                                                                                                                                                                                 
opcache.jit_hot_func => 127 => 127                                                                                                                                                                          
opcache.jit_hot_loop => 64 => 64                                                                                                                                                                            
opcache.jit_hot_return => 8 => 8                                                                                                                                                                            
opcache.jit_hot_side_exit => 8 => 8                                                                                                                                                                         
opcache.jit_max_exit_counters => 8192 => 8192                                                                                                                                                               
opcache.jit_max_loop_unrolls => 8 => 8                                                                                                                                                                      
opcache.jit_max_polymorphic_calls => 2 => 2                                                                                                                                                                 
opcache.jit_max_recursive_calls => 2 => 2                                                                                                                                                                   
opcache.jit_max_recursive_returns => 2 => 2                                                                                                                                                                 
opcache.jit_max_root_traces => 1024 => 1024                                                                                                                                                                 
opcache.jit_max_side_traces => 128 => 128                                                                                                                                                                   
opcache.jit_prof_threshold => 0.005 => 0.005                                                                                                                                                                
opcache.lockfile_path => /tmp => /tmp                                                                                                                                                                       
opcache.log_verbosity_level => 1 => 1                                                                                                                                                                       
opcache.max_accelerated_files => 10000 => 10000                                                                                                                                                             
opcache.max_file_size => 0 => 0                                                                                                                                                                             
opcache.max_wasted_percentage => 5 => 5                                                                                                                                                                     
opcache.memory_consumption => 128 => 128                                                                                                                                                                    
opcache.opt_debug_level => 0 => 0                                                                                                                                                                           
opcache.optimization_level => 0x7FFEBFFF => 0x7FFEBFFF                                                                                                                                                      
opcache.preferred_memory_model => no value => no value                                                                                                                                                      
opcache.preload => no value => no value                                                                                                                                                                     
opcache.preload_user => no value => no value                                                                                                                                                                
opcache.protect_memory => Off => Off                                                                                                                                                                        
opcache.record_warnings => Off => Off                                                                                                                                                                       
opcache.restrict_api => no value => no value                                                                                                                                                                
opcache.revalidate_freq => 2 => 2                                                                                                                                                                           
opcache.revalidate_path => Off => Off                                                                                                                                                                       
opcache.save_comments => On => On                                                                                                                                                                           
opcache.use_cwd => On => On                                                                                                                                                                                 
opcache.validate_permission => Off => Off                                                                                                                                                                   
opcache.validate_root => Off => Off                                                                                                                                                                         
opcache.validate_timestamps => On => On

I think this should be the same settings as in web.

@kevinpapst
Copy link
Collaborator Author

I don't understand that docker container.

  1. Enabling opcache on the CLI is not the best idea, I vote against that.
  2. Are you sure that web is using the same php.ini?
  3. Can you double check the config for web => creating a info.php file that you open via browser / through fpm.

@LiaraAlis
Copy link
Contributor

  1. What makes you think that OPcache is enabled on the CLI? opcache.enable_cli is Off
  2. Not sure, but it looks like.
  3. Of course. See table below.

Zend OPcache

Opcode Caching Up and Running
Optimization Enabled
SHM Cache Enabled
File Cache Disabled
JIT Disabled
Startup OK
Shared memory model mmap
Cache hits 1919995
Cache misses 2979
Used memory 48407616
Free memory 85810112
Wasted memory 0
Interned Strings Used memory 4662640
Interned Strings Free memory 1628352
Cached scripts 2977
Cached keys 4087
Max keys 16229
OOM restarts 0
Hash keys restarts 0
Manual restarts 0
Directive Local Value Master Value
opcache.blacklist_filename no value no value
opcache.consistency_checks 0 0
opcache.dups_fix Off Off
opcache.enable On On
opcache.enable_cli Off Off
opcache.enable_file_override Off Off
opcache.error_log no value no value
opcache.file_cache no value no value
opcache.file_cache_consistency_checks On On
opcache.file_cache_only Off Off
opcache.file_update_protection 2 2
opcache.force_restart_timeout 180 180
opcache.huge_code_pages Off Off
opcache.interned_strings_buffer 8 8
opcache.jit tracing tracing
opcache.jit_bisect_limit 0 0
opcache.jit_blacklist_root_trace 16 16
opcache.jit_blacklist_side_trace 8 8
opcache.jit_buffer_size 0 0
opcache.jit_debug 0 0
opcache.jit_hot_func 127 127
opcache.jit_hot_loop 64 64
opcache.jit_hot_return 8 8
opcache.jit_hot_side_exit 8 8
opcache.jit_max_exit_counters 8192 8192
opcache.jit_max_loop_unrolls 8 8
opcache.jit_max_polymorphic_calls 2 2
opcache.jit_max_recursive_calls 2 2
opcache.jit_max_recursive_returns 2 2
opcache.jit_max_root_traces 1024 1024
opcache.jit_max_side_traces 128 128
opcache.jit_prof_threshold 0.005 0.005
opcache.lockfile_path /tmp /tmp
opcache.log_verbosity_level 1 1
opcache.max_accelerated_files 10000 10000
opcache.max_file_size 0 0
opcache.max_wasted_percentage 5 5
opcache.memory_consumption 128 128
opcache.opt_debug_level 0 0
opcache.optimization_level 0x7FFEBFFF 0x7FFEBFFF
opcache.preferred_memory_model no value no value
opcache.preload no value no value
opcache.preload_user no value no value
opcache.protect_memory Off Off
opcache.record_warnings Off Off
opcache.restrict_api no value no value
opcache.revalidate_freq 2 2
opcache.revalidate_path Off Off
opcache.save_comments On On
opcache.use_cwd On On
opcache.validate_permission Off Off
opcache.validate_root Off Off
opcache.validate_timestamps On On

@kevinpapst
Copy link
Collaborator Author

Thank you very much 👍

I just saw opcache.enable => On. Missed the second setting. Off is better on cli, so we are good for that one.

@kevinpapst kevinpapst marked this pull request as ready for review January 11, 2023 09:56
@LiaraAlis
Copy link
Contributor

@kevinpapst Should I add your changes in this PR to my Dockerfile and try your changes?

@kevinpapst
Copy link
Collaborator Author

You could test if they work, yes please. I guess you will not see much difference for a single user though.

But at least the validate_timestamps makes a huge IO difference, especially with many users.

@LiaraAlis
Copy link
Contributor

I tried it out but it seems that your changes doesn't have any effect. It seems that the replace doesn't work. {{php.ini}} values stays on default.
But I also noticed that this line also have no effect:

sed -i "s/expose_php = On/expose_php = Off/g" /usr/local/etc/php/php.ini && \

www-data@eeb903d9b49d:~/html$ cat /usr/local/etc/php/php.ini | grep expose_php                                                                                                                              
expose_php = On

I used build apache-1.30.2-prod.
@tobybatch Maybe this is the wrong place for these changes?

@tobybatch tobybatch mentioned this pull request Jan 22, 2023
@tobybatch
Copy link
Owner

There was core bug with my sed operations in the Dockerfile and startup.sh.

@kevinpapst I've lifted your code into a new PR #452 along with the bug fix.

@tobybatch tobybatch closed this Jan 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Use opcache & apcu / Increase performance
3 participants