Tag Archives: ruby

Gunicorn timeout error: [1] [critical] worker timeout [How to Solve]

1. Problem description

In a web project built with gunicorn + flash, because the machine learning model is used, the model needs to be loaded when requesting the interface for the first time. The model is loaded quickly when running locally, so it runs normally. The application is deployed to the server using docker (the model is mounted to the container through volume), The first request to load the model takes a long time, and the following errors are reported:

[2021-09-11 07:22:33 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:12)
[2021-09-11 07:22:35 +0000] [12] [INFO] Worker exiting (pid: 12)

Gunicorn ‘green Unicorn’ is a python WSGI HTTP server for UNIX. It is a pre forked worker model transplanted from Ruby’s Unicorn project. Gunicorn server is widely compatible with various web frameworks, with simple implementation, less use of server resources and quite fast speed.

2. Cause analysis

It can be seen from the error message that gunicorn’s worker process timed out, causing the process to exit and restart
refer to the official document of gunicorn and the description shown in the figure below:

3. Solution

From the documentation on the official website, we can know that the default timeout of gunicorn is 30s. If it exceeds 30s, the worker process will be killed and restarted.

Therefore, to solve this problem, you only need to set a large timeout: gunicorn to set the timeout

gunicorn -w 2 -b 0.0.0.0:4343  manage:app --timeout 120 

Add: -- timeout 120 to gunicorn’s startup command, indicating that the timeout is set to 120 seconds. Configure the timeout in the gunicorn. Conf.py configuration file of gunicorn

workers = 4  # Define the number of processes to be opened for processing requests at the same time, adjusted appropriately according to site traffic
worker_class = "gevent" # Use the gevent library to support asynchronous processing of requests and improve throughput
bind = "0.0.0.0:8500" # Listen to IP relaxation to facilitate communication between Dockers and between Dockers and hosts
timeout = 120 # Set the timeout to 120 seconds

For more configuration of the gunicorn. Conf.py file, see the official website

DB: the solution of table already exist when migrating

        When running rake DB: migrate, you sometimes find an error in rake abort. Rake says that a table already exists, so it can’t do the work of this migrate. This table does exist, so how can rake skip this table or force it to be overridden?There is one area that needs to be modified:

Original migrate file:

Ruby code

 

    class   CreateProducts  & lt;   ActiveRecord::Migration      def   self.up        create_ table  : products   do  | t|          t.column  : title,  : string          t.column  : description,  : text          t.column  : image_ url,  : string        end      end        def   self.down        drop_ table  : products      end    end   

    Modified migrate file:

    Ruby code

     

      class   CreateProducts  & lt;   ActiveRecord::Migration      def   self.up        create_ table  : products,  : force  =& gt;   true   do  | t|          t.column  : title,  : string          t.column  : description,  : text          t.column  : image_ url,  : string        end      end        def   self.down        drop_ table  : products      end    end   

      Do you see that in create_ In the parameter of table, add: force = & gt; True.

How to Solve Cocoapods Installation Failure

The scene appears

Recently, I replaced a 512 large hard disk and re installed MacOS 10.15. When installing cocoapods, the following error occurred

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20210324-1667-1wwdce5.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi... yes
checking for ffi_prep_closure_loc() in -lffi... yes
checking for ffi_prep_cif_var()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
creating extconf.h
creating Makefile

current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/ext/ffi_c
make "DESTDIR=" clean

current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0/ext/ffi_c
make "DESTDIR="
make: *** No rule to make target `"/Volumes/macOS', needed by `AbstractMemory.o'.  Stop.

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.0 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.0/gem_make.out

Solution:

    1. it may be the problem of system version, which is not compatible with the latest version, so install the old version directly. I encountered the problem is 2021.07.06, the latest version is 1.10.1, find a 1.9.32020.05 release, should be compatible with 10.15
# Specify version to install
sudo gem install -n /usr/local/bin cocoapods -v 1.9.3
      1. use brew to install
brew install cocoapods

Ruby Install Error running ‘requirements_osx_brew_update_system ruby-2.3.1

Operating system: macOS 10.12.1

Install Ruby 2.3.1 error

The specific error message is as follows.

chaorenbuhuifeideMacBook-Air:~ chaorenbuhuifei$ rvm install 2.3.1

Searching for binary rubies, this might take some time.

Found remote file https://rubies.travis-ci.org/osx/10.12/x86_64/ruby-2.3.1.tar.bz2

Checking requirements for osx.

Installing requirements for osx.

Updating system…….

Error running ‘requirements_osx_brew_update_system ruby-2.3.1′,

showing last 15 lines of /Users/chaorenbuhuifei/.rvm/log/1481424365_ruby-2.3.1/update_system.log

https://github.com/Homebrew/homebrew/wiki/Common-Issues

and make sure `brew update` works before continuing.’

++ rvm_pretty_print stderr

++ case “${rvm_pretty_print_flag:=auto}” in

++ case “${TERM:-dumb}” in

++ case “$1” in

++ [[ -t 2 ]]

++ return 1

++ printf %b ‘Failed to update Homebrew, follow instructions here:

https://github.com/Homebrew/homebrew/wiki/Common-Issues

and make sure `brew update` works before continuing.\n’

Failed to update Homebrew, follow instructions here:

https://github.com/Homebrew/homebrew/wiki/Common-Issues

and make sure `brew update` works before continuing.

++ return 1

Requirements installation failed with status: 1.

Error running ‘requirements_osx_brew_update_system ruby-2.3.1’

 

How to Solve:

Step 1:

$ brew install autoconf automake libtool pkg-config apple-gcc42 libyaml readline libxml2 libxslt libksba openssl sqlite

This method will report error

Error: No available formula with the name “apple-gcc42”

==> Searching for similarly named formulae…

Error: No similarly named formulae found.

==> Searching taps…

This formula was found in a tap:

homebrew/dupes/apple-gcc42

To install it, run:

brew install homebrew/dupes/apple-gcc42

 

Step 2:

$brew install homebrew/dupes/apple-gcc42

 

then re-install

$rvm install 2.3.1

 

 

Ror deployed to heroku has application error and code = H10 desc = “app crashed” problems

1. Preparation before problem discovery
When I was reading Learn Python In Hard Way, I saw that there is a wonderful thing the author talks about. There is a boring thing she does before doing something funny, called Yak shaving. Things like setup, configuration and so on before you learn a language or technology.

I heard a fellow student say that if you do the Web, you can learn ROR. I looked it up and found Ruby on Rails as its author —

David Heinemeier Hansson is also a rather amazing programmer. Then I wanted to learn Ruby systematically this time, but I found a lot of details, so I wanted to change another way of learning and directly learn ROR.

About this kind of study way, I searched some experience to answer again. One senior summed it up very well. Three books later.

1. HeadFirst HTML AND CSS

2. The Linux Command Line

3. Pro Git

From the basic front end, Linux as a whole and basic shell, as well as Git tools. Skip the first according to individual knowledge, pick the knowledge point that does not understand to read, the latter two read more carefully. I found myself using Git, not knowing that snapshot is the same thing, and how the control flow of Git is different from SVN. For the first time, I found that double-click in Linux can be copied, and middle mouse button can be pasted directly.

2. Identify problems

I’ll watch Ruby on Rails Tutorial later, and the first chapter is Yak Shaving.

Configure the ROR environment yourself, and then formally deploy to Heroku. And then there’s the problem. Application Error and code=H10 desc=”App Chinese “problem.

Heroku itself can see the error by clicking View Logs

at=error code=H10 desc="App crashed" method=GET path=/ host=xxx.herokuapp.com fwd= dyno= queue= wait= connect= service= status=503 bytes=

3. Problem solving
This doesn’t tell you what the problem is. Keep checking. http://stackoverflow.com/questions/13496827/heroku-deployment-error-h10-app-crashed

As in the first answer, type Heroku Run Rails Console. You can fix the trouble.

2016-02-29T05:18:58.740439+00:00 app[web.1]: /app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails/helpers.rb:11:in `<top (required)>': uninitialized constant Sass::Script (NameError)
2016-02-29T05:18:58.740461+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails.rb:8:in `require'
2016-02-29T05:18:58.740463+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails.rb:8:in `<top (required)>'
2016-02-29T05:18:58.740463+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass-rails.rb:1:in `require'
2016-02-29T05:18:58.740464+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass-rails.rb:1:in `<top (required)>'
2016-02-29T05:18:58.740465+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `require'
2016-02-29T05:18:58.740466+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
2016-02-29T05:18:58.740466+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `each'
2016-02-29T05:18:58.740469+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `block in require'
2016-02-29T05:18:58.740470+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `each'
2016-02-29T05:18:58.740470+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `require'
2016-02-29T05:18:58.740471+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler.rb:134:in `require'
2016-02-29T05:18:58.740472+00:00 app[web.1]:    from /app/config/application.rb:7:in `<top (required)>'
2016-02-29T05:18:58.740473+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `require'
2016-02-29T05:18:58.740473+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:78:in `block in server'
2016-02-29T05:18:58.740474+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `tap'
2016-02-29T05:18:58.740475+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:75:in `server'
2016-02-29T05:18:58.740475+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
2016-02-29T05:18:58.740476+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/commands.rb:17:in `<top (required)>'
2016-02-29T05:18:58.740477+00:00 app[web.1]:    from bin/rails:9:in `require'
2016-02-29T05:18:58.740477+00:00 app[web.1]:    from bin/rails:9:in `<main>'
2016-02-29T05:18:59.458586+00:00 heroku[web.1]: State changed from starting to crashed
2016-02-29T05:18:59.444429+00:00 heroku[web.1]: Process exited with status 1

according to

/app/vendor/bundle/ruby/2.2.0/gems/sass-rails-5.0.1/lib/sass/rails/helpers.rb:11:in `<top (required)>': uninitialized constant Sass::Script (NameError)

You can guess that it’s the version of SASS-Rails in the gem file. I suddenly remembered this detail.

In fact, according to the third edition of the book’s Gemfile configuration, the book configuration is gem ‘sass-Rails ‘,’5.0.0.beta1’, this step when executing the bundle install will report an error. I’m just going to get rid of beta1.

Because of this error, I changed it to version 5.0.1. But it’s still wrong. I had no idea last week. After you reorganize your thoughts today, check this mistake again.

Found the answer: http://stackoverflow.com/questions/29594420/rails-tutorial-error-with-cloud-9

It should be configured as gem ‘sass-Rails ‘,’5.0.2’.

Successful official deployment of Hello World.

Recently I watched The Secret of Music, a behind-the-scenes work on a song, and as a programmer I should be able to see the same respect for my profession.

Recently, it seems that he suddenly has a soft rib, and suddenly he has armor. Become more determined.

comparison of Fixnum with nil failed

  def validate
    errors.add(:score, '您的积分不够') if (!self.cur_ask_score.nil?) && (self.score > self.cur_ask_score)
  end

, that’s the validation in the model.

, I started with

  def validate
    errors.add(:score, '您的积分不够') if self.score > self.cur_ask_score
  end

results in the following error:

comparison of Fixnum with nil failed

just now, I ran into a weird problem — the usual assumption is that saving a successful operation doesn’t work!

this kind of problem, generally is the model validation failure caused by!

Ubuntu20.04 installing RVM error curl: (7) failed to connect to raw.githubusercontent.com port 443: Operation timed

Add this code sudo/etc/hosts below
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com