CPU utilisation spikes to 100% on Rails application startup on ARM platform

I am developing Rails application(ruby2.1.5 and rails4.2.0) for embedded
device.I have observed that every time when I run Rails Application,CPU
utilization spikes to 100% for few seconds on startup

My system info is as follows:

   root@wandboard-quad:~/test3# uname -a
    Linux wandboard-quad 3.0.35-4.0.0-wandboard+gd35902c #1 SMP PREEMPT
Wed Aug 6 12:42:22 IST 2014 armv7l GNU/Linux

I have followed following steps:

1. Created new application with following command:

rails new test3

Started rails server

rails server

I have got following cpu utillization on startup

1569 root 20 0 10392 6960 2472 R 29 0.4 0:00.88 ruby
**1579 root 20 0 25404 19m 3448 R 97 1.1 0:03.04 ruby
1579 root 20 0 44416 35m 4196 R 100 1.9 0:06.04 ruby**
1579 root 20 0 61084 51m 4460 S 76 2.8 0:08.32 ruby
1579 root 20 0 62148 52m 4516 S 5 2.9 0:08.47 ruby
1579 root 20 0 62148 52m 4516 S 0 2.9 0:08.48 ruby
1579 root 20 0 62148 52m 4516 S 0 2.9 0:08.49 ruby
1579 root 20 0 62148 52m 4516 S 0 2.9 0:08.50 ruby
After digging further using BYEBUG ,I think cpu spikes in
commands_tasks.rb file in method server at following line

require APP_PATH

what might be reason for CPU going high on startup?
I have tried this various webservers like Webbrick,thin,unicorn.

I am developing Rails application(ruby2.1.5 and rails4.2.0) for embedded

device.I have observed that every time when I run Rails Application,CPU

utilization spikes to 100% for few seconds on startup

That’s just the way it is - it’s preloading all of your app’s code. (the config.eager_load and config.eager_load_paths control this)

Fred

Hi Fred,

Thanks for your response.

I tried to run application in Production mode ,but still cpu is hitting
100% on startup.

What I think is it is hitting 100% due to

require 'rails/all'

at the instance when it tries to load active_record railtie.rb

require "#{framework}/railtie"

Do you think it is normal to get such high cpu utilisation on startup ?
If I run same application on x86 linux environment ,it does not take
that much cpu utilisation.

BR,
Chetan

Actually, it probably does hit 100%, just for a fraction of the time and you don't see it. ARM is simply a much slower processor.

What do you mean by 'startup'. Do you mean starting the server (which
should only happen once, unless you are hitting the website so
infrequently that the server is shut down)? It should certainly not
happen at each request when you are in production mode.

Colin

What do you mean by 'startup'. Do you mean starting the server (which
should only happen once, unless you are hitting the website so
infrequently that the server is shut down)? It should certainly not
happen at each request when you are in production mode.

Colin

Yes,'Startup' means when I start the server.

BR,
Chetan

I would have thought this is completely normal and expected behavior for the ARM platform.

In that case why are you worried about it, or is it just academic interest?

Colin

Colin Law wrote in post #1166558:

What do you mean by 'startup'. Do you mean starting the server (which
should only happen once, unless you are hitting the website so
infrequently that the server is shut down)? It should certainly not
happen at each request when you are in production mode.

Colin

Yes,'Startup' means when I start the server.

In that case why are you worried about it, or is it just academic
interest?

Colin

I am currently running this application on ARMV7 2GB QuadCore
processor.There is no other application except this is running at the
moment on board.
But actually what I am going to get is at the max 1GB ram and there will
be at least 3 other applications that will be running along with this.So
I am worried its performance impact will be more at that time.

another thing I am new to Ruby on rails and Yes,I was not sure whether
this is the normal case or not or is it something that I am missing
while compiling ruby on rails?

BR,
Chetan

Hi,

my app is on Ruby 2.1.2 and Rails 4.1.5

like the subject states I would expect

current_user.account.employees.includes(:entrances).where( 'entrances.clocked_at' => @month_range)

to return all employees (to this current_user’s account) - and any entrances

But I’m left with the employees that has entrances in the month_range

[

that looks like this:

SELECT employees.id AS t0_r0, employees.name AS t0_r1, employees.last_seen AS t0_r2, employees.created_at AS t0_r3, employees.updated_at AS t0_r4, employees.punch_clock_id AS t0_r5, employees.account_id AS t0_r6, employees.born_at AS t0_r7, entrances.id AS t1_r0, entrances.employee_id AS t1_r1, entrances.clocked_at AS t1_r2, entrances.created_at AS t1_r3, entrances.updated_at AS t1_r4, entrances.entrance_type AS t1_r5 FROM employees LEFT OUTER JOIN entrances ON entrances.employee_id = employees.id WHERE employees.account_id = 2 AND (entrances.clocked_at BETWEEN ‘2015-01-01’ AND ‘2015-01-31’) ORDER BY employees.id, entrances.clocked_at

]

If, however, I settle for

current_user.account.employees.includes(:entrances)

I get all employees but than I get all the entrances loaded into memory as well

[

that looks like:

Employee Load (0.2ms) SELECT employees.* FROM employees WHERE employees.account_id = 2

Entrance Load (0.2ms) SELECT entrances.* FROM entrances WHERE entrances.employee_id IN (1, 2)

Entrance Load (0.3ms) SELECT entrances.* FROM entrances WHERE entrances.employee_id = 1 AND (entrances.clocked_at BETWEEN ‘2015-01-01’ AND ‘2015-01-31’)

Entrance Load (0.4ms) SELECT entrances.* FROM entrances WHERE entrances.employee_id = 2 AND (entrances.clocked_at BETWEEN ‘2015-01-01’ AND '2015-01-31’)

]

The correct statement is

SELECT

employees.id AS t0_r0, employees.name AS t0_r1, employees.last_seen AS t0_r2, employees.created_at AS t0_r3, employees.updated_at AS t0_r4, employees.punch_clock_id AS t0_r5, employees.account_id AS t0_r6, employees.born_at AS t0_r7, entrances.id AS t1_r0, entrances.employee_id AS t1_r1, entrances.clocked_at AS t1_r2, entrances.created_at AS t1_r3, entrances.updated_at AS t1_r4, entrances.entrance_type AS t1_r5

FROM

`employees`

LEFT OUTER JOIN

`entrances` ON `entrances`.`employee_id` = `employees`.`id` AND (`entrances`.`clocked_at` BETWEEN '2015-01-01' AND '2015-01-31’)

WHERE

`employees`.`account_id` = 2

but how do I write that “the Rails way”

cheers

Walther

Colin Law wrote in post #1166558:

What do you mean by 'startup'. Do you mean starting the server (which
should only happen once, unless you are hitting the website so
infrequently that the server is shut down)? It should certainly not
happen at each request when you are in production mode.

Colin

Yes,'Startup' means when I start the server.

In that case why are you worried about it, or is it just academic
interest?

Colin

I am currently running this application on ARMV7 2GB QuadCore
processor.There is no other application except this is running at the
moment on board.
But actually what I am going to get is at the max 1GB ram and there will
be at least 3 other applications that will be running along with this.So
I am worried its performance impact will be more at that time.

But since server startup only happens very occasionally and it is only
for a few seconds why would processor utilisation be an issue? Also
what has that got to do with the amount of RAM? Whether you will have
sufficient RAM is independent of processor utilisation.

Colin

Colin Law wrote in post #1166588: