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

102 views
Skip to first unread message

Chetan Raskar

unread,
Jan 12, 2015, 12:44:42 AM1/12/15
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Jan 12, 2015, 5:56:44 AM1/12/15
to rubyonra...@googlegroups.com


On Monday, January 12, 2015 at 5:44:42 AM UTC, Ruby-Forum.com User wrote:
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

Chetan Raskar

unread,
Jan 12, 2015, 7:32:14 AM1/12/15
to rubyonra...@googlegroups.com
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

Scott Ribe

unread,
Jan 12, 2015, 9:11:08 AM1/12/15
to rubyonra...@googlegroups.com, Chetan Raskar
On Jan 12, 2015, at 5:31 AM, Chetan Raskar <li...@ruby-forum.com> wrote:
>
> 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.

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.

--
Scott Ribe
scott...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Colin Law

unread,
Jan 12, 2015, 11:28:49 AM1/12/15
to rubyonra...@googlegroups.com
On 12 January 2015 at 12:31, Chetan Raskar <li...@ruby-forum.com> wrote:
> Hi Fred,
>
> Thanks for your response.
>
> I tried to run application in Production mode ,but still cpu is hitting
> 100% on startup.

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

Chetan Raskar

unread,
Jan 12, 2015, 12:14:30 PM1/12/15
to rubyonra...@googlegroups.com
>
> 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.

Timothy Mukaibo

unread,
Jan 12, 2015, 3:24:21 PM1/12/15
to rubyonra...@googlegroups.com
I would have thought this is completely normal and expected behavior for the ARM platform.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/552e7b876a9a61eff215edb5d9688935%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Colin Law

unread,
Jan 12, 2015, 3:30:54 PM1/12/15
to rubyonra...@googlegroups.com
On 12 January 2015 at 17:13, Chetan Raskar <li...@ruby-forum.com> wrote:
>>
>> 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

Chetan Raskar

unread,
Jan 13, 2015, 12:11:55 AM1/13/15
to rubyonra...@googlegroups.com
Colin Law wrote in post #1166558:
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?

Walther Diechmann

unread,
Jan 13, 2015, 3:04:24 AM1/13/15
to Ruby
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

unread,
Jan 13, 2015, 4:43:42 AM1/13/15
to rubyonra...@googlegroups.com
On 13 January 2015 at 05:10, Chetan Raskar <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1166558:
>> On 12 January 2015 at 17:13, Chetan Raskar <li...@ruby-forum.com> wrote:
>>>>
>>>> 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

>
> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/041334f753d7e5af6ce336ae2a2f3f71%40ruby-forum.com.

Chetan Raskar

unread,
Jan 14, 2015, 9:00:45 AM1/14/15
to rubyonra...@googlegroups.com
Colin Law wrote in post #1166588:
> On 13 January 2015 at 05:10, Chetan Raskar <li...@ruby-forum.com> wrote:
>>>> Yes,'Startup' means when I start the server.
>> 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

Hi Colin,

Yes ,You are correct and also I guess I need to work on my basic
knowledge of cpu and ram.
Thanks and regards,
Chetan Raskar
Reply all
Reply to author
Forward
0 new messages