Skip to content

Implements PHP-FPM/FCGI for Apache for 7.0.3, Flex 3.19, and Flex Edge #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

Jmevorach
Copy link
Contributor

Implements PHP-FPM/FCGI for Apache. More information about PHP-FPM/FCGI for Apache on Alpine can be found here (https://wiki.alpinelinux.org/wiki/Apache_with_php-fpm). Tested for 7.0.3.

Implements PHP-FPM/FCGI for Apache. More information about PHP-FPM/FCGI for Apache on Alpine can be found here (https://wiki.alpinelinux.org/wiki/Apache_with_php-fpm). Tested for 7.0.3.
@Jmevorach
Copy link
Contributor Author

Wanted to write down some thoughts before I forgot them.

  • The performance gains we get from implementing PHP-FPM/FCGI like this are amazing. Under load testing this new version used slightly less CPU and RAM, was more stable (i.e. less 5xx errors, etc. etc.) and was consistently achieving sub 0.2s response times compared to response times that often went as high as ~0.8s.
  • I spent a lot of time reviewing the repositories. Beyond this, the only way I see to relatively easily achieve any additional performance gains, aside from editing the application code (i.e. any code found in openemr/openemr), would be to use Roadrunner in place of Apache as an application server.

P.S.: I'm going to be busy for a bit but I should be able to respond to messages again here in around 2 weeks.

@bradymiller
Copy link
Member

hi @Jmevorach ,
Really neat stuff! I think it makes sense to bring in this PR and build a new flex docker so we can the take advantage of all the testing it will get by devs using the easy docker environment. Note the 7.0.3 and edge dockers are built automatically nightly.

@Jmevorach
Copy link
Contributor Author

Thanks @bradymiller! And sure sounds good. Happy testing 🙂!

@bradymiller
Copy link
Member

time to pull the trigger :)

@bradymiller bradymiller merged commit 8aed4b0 into openemr:master Mar 5, 2024
@bradymiller
Copy link
Member

hi @Jmevorach ,
Got this now on the main flex docker (easy dev docker environment). Does this work out of box or is more configuration required? Asking since not working out of box (the Server API is Apache 2.0 Handler and not FPM/FastCGI in phpinfo() call).

@Jmevorach
Copy link
Contributor Author

Hi @bradymiller . That is interesting!

I definitely saw those performance gains I mentioned above. In light of that my assumption, unless I did something wrong, is that there's something causing phpinfo() to report on unexpected results.

I found this Stack Overflow page discussing an example in which phpinfo() produces unexpected results that can be found here.

I think this serves a good datapoint to show that it is possible for phpinfo() to return unexpected results. However as to what exactly is causing the issue here I'm not sure.

Are you also seeing performance gains on your end?

@bradymiller
Copy link
Member

bradymiller commented Mar 6, 2024

Hi @Jmevorach ,

Out of box, appears the fastcgi is not working:
In OpenEMR, at Admin->System->Diagnostic, SAPI setting is apache2handler

I was able to get the fpm-fcgi working by going through the steps at https://wiki.alpinelinux.org/wiki/Apache_with_php-fpm:

  • (needed to apk add openrc to be able to do the rc-service stuff for php-fpm83 which also required adding a file via touch to make it work because of some funky thing and seemed to have to restart the docker couple times while doing this)
  • Uncomment the mpm_event module and comment the mpm_prefork module
  • Commented out lines in /etc/apache2/conf.d/php8-module.conf
  • set user/group to apache in /etc/php83/php-fpm.d/www.conf
  • did the rc-service php-fpm83 reload
  • and then voila, it worked (note needed to placed index.php in the web path for it to show the OpenEMR login) and now see SAPI setting is fpm-fcgi

image

@bradymiller
Copy link
Member

bradymiller commented Mar 6, 2024

I should of also added another way to prove that php-fpm is up an running is via the ps aux command:

/var/www/localhost/htdocs/openemr # ps aux
PID   USER     TIME  COMMAND
    1 root      0:00 {openemr.sh} /bin/sh ./openemr.sh
   12 root      0:02 /usr/sbin/httpd -D FOREGROUND
   15 root      0:00 /usr/sbin/rotatelogs -n 5 /var/log/apache2/error.log 86400
   16 root      0:00 /usr/sbin/rotatelogs -n 5 /var/log/apache2/access.log 86400
   17 apache    0:24 /usr/sbin/httpd -D FOREGROUND
   18 apache    0:22 /usr/sbin/httpd -D FOREGROUND
   27 apache    0:22 /usr/sbin/httpd -D FOREGROUND
  120 root      0:00 sh
  363 root      0:02 {php-fpm83} php-fpm: master process (/etc/php83/php-fpm.conf)
  399 apache    0:01 {php-fpm83} php-fpm: pool www
  400 apache    0:02 {php-fpm83} php-fpm: pool www
  406 apache    0:21 /usr/sbin/httpd -D FOREGROUND
  437 apache    0:01 node /var/www/localhost/htdocs/openemr/ccdaservice/node_modules/oe-cqm-service/server.js
  444 apache    0:00 {php-fpm83} php-fpm: pool www
  451 root      0:00 ps aux

If don't do the steps above, then there are no entries for php-fpm processes

@bradymiller
Copy link
Member

@Jmevorach
btw, I have no clue why simply installing apache2-proxy gives you such performance improvements (figure is not the php83-fpm package since not being used yet) and I don't really have a structure set up for testing performance ( @adunsulag may have one I think). I am also super curious what you see in your performance testing when fpm-fcgi is officially working via above steps.

@Jmevorach
Copy link
Contributor Author

Jmevorach commented Mar 6, 2024

Alright well I'm stumped 😂. Yeah I have no idea what could have accounted for that. I noticed a markedly different response time and I was even able to replicate the results again today. I noticed it go from 0-0.8s to 0.0 - 0.4s . I'm going to try to get to the bottom of this just out of my own sense of curiosity.

Also I'm 100% convinced. I definitely goofed on this one. My bad; apologies 🤦.

Look forward to testing that once it's implemented! I'd offer to take it up myself but I'm going to be pretty busy for a bit and I also don't exactly have a good track record on implementing php-fpm 😊.

Still happy to test once we get it figured out though. Thanks for catching this one and calling me out on it!

@bradymiller
Copy link
Member

hi @Jmevorach ,
Thinking something about the apache2-proxy module is improving performance (it does seem faster on my testing also :) ). Found nice primer into what is happening with php-fpm and fcgi is here (including why then get to change the apache MPM from pre-fork to event in this setting):
https://www.digitalocean.com/community/tutorials/how-to-configure-apache-http-with-mpm-event-and-php-fpm-on-ubuntu-18-04
Gonna play around with this some more to see if a nicer way to get this working (or at least have a launching board ready in the docker for users that want to configure it and hopefully via a docker setting).

@bradymiller
Copy link
Member

hi @Jmevorach , fresh off the press :)
#385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants