Previously, the application worked on a shared hosting without a docker container and the performance was good. After transferring to a dedicated server, the application was made through a docker container and a performance problem appeared. The developer assured that there was a problem with the old Ruby, but if before everything worked within the normal range, now the application restarts every 6 hours trough cron (docker-compose down) to maintain normal speed. Application handles concurrency poorly.
The main problem is that initial rendering speed is:
Processing CatalogController#index (for 127.0.0.1 at 2023-09-06 19:22:06) [GET] Parameters: {"controller"=>"catalog", "language"=>"ru", "action"=>"index"} Rendering template within layouts/main Rendering catalog/index Completed in 330ms (View: 300, DB: 30) | 200 OK [http://localhost/]
Than after 300 requests it slows to:
Processing CatalogController#index (for 127.0.0.1 at 2023-09-06 19:22:06) [GET] Parameters: {"controller"=>"catalog", "language"=>"ru", "action"=>"index"} Rendering template within layouts/main Rendering catalog/index Completed in 1266ms (View: 1233, DB: 37) | 200 OK [http://localhost/]
When I try to use ab -n 100 http://localhost:3000/ it shows result like:
Concurrency Level: 1
Time taken for tests: 33.883 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 6796500 bytes
HTML transferred: 6764800 bytes
Requests per second: 2.95 [#/sec] (mean)
Time per request: 338.831 [ms] (mean)
Time per request: 338.831 [ms] (mean, across all concurrent requests)
Transfer rate: 195.89 [Kbytes/sec] received
Code in Dockerfile that builds application:
FROM centos:7
SHELL ["/bin/bash", "-c"]
RUN yum update -y && yum -y install gpg curl which wget ImageMagick-devel mysql mysql-devel libxml2-devel libxslt libxslt-devel
#Install RVM
RUN gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
RUN \curl -sSL https://get.rvm.io | bash -s stable
#Install Ruby
RUN source /etc/profile.d/rvm.sh && rvm install 1.8.7
#Install Ruby Gems
RUN source /etc/profile.d/rvm.sh && rvm use 1.8.7 && gem install -v=2.3.5 rails && gem install bundler -v=1.3.5 && gem install rubygems-update -v 1.3.7 && update_rubygems --version=1.3.7 && gem install mime-types -v=1.17.2 && gem install russian -v=0.2.7 && gem install httparty -v=0.7.2 && gem install mini_mime -v=1.1.2 && gem install yandex_inflect -v=0.1.0 && PATH="/app/ImageMagick-6.8.0-10/Magick++/bin:$PATH" gem install rmagick -v=2.13.2 && gem install mechanize -v=0.8.5 && gem install geoip -v 1.1.2 && gem install rdoc -v=3.9.2 && gem install mysql -v=2.9.1 && gem install nokogiri -v=1.4.4 && gem install daemons -v=1.1.0 && gem install thin -v=1.7.0
WORKDIR /app
RUN mkdir /app/tmp
CMD source /etc/profile.d/rvm.sh && rvm use 1.8.7 && script/server thin -p 3000 -e production
Maybe someone knows what can cause such a behavior?
I have tried to install thin server instead of a WebBrick but it didn't resolve the problem. And only solution for now is docker-compose down command but it restarts application entirely for almost 16 seconds. Lookes through a code and didn't find code that can slow down the application.
Possible solutions to the problem:
- Correctly configure the docker container (the application did not work on docker before, so the problem may be in its settings)
- Install unicorn or passenger (it worked on webrick during the transfer, then transferred to thin, but it didn't help much)
- Install some additional gems (before, more gems were installed on the hosting, but now only the most necessary ones).
- It is necessary to transfer the application to a new version of Ruby on Rails (if there is no other way out, then you have to do it)
Aucun commentaire:
Enregistrer un commentaire