# Periodically\_call\_remote eating up lots of CPU

**URL:** <https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094>\
**Category:** Rails\
**Created:** [March 17, 2007, 7:40am UTC](https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094 "2007-03-17T07:40:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [March 17, 2007, 7:40am UTC](https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094/1 "2007-03-17T07:40:33Z")

</div>

Hi all,

I am having a problem where when I call periodically\_call\_remote the  
CPU usage goes really high and I have to kill the browser to return  
the system to normal. I have the following remote call:

\<%= periodically\_call\_remote :url =\> {:action =\> ‘\_live\_now’ },  
:update =\> ‘live\_now\_list’,  
:frequency =\> 10 %\>

This works fine, at the start. After about 20/30 seconds the CPU  
starts rising, to 20%, 50%, 70% and higher.

At first I have the above remote call in a partial (\_live\_now.rhtml):

… stuff…

\<%= periodically\_call\_remote :url =\> {:action =\> ‘\_live\_now’ },  
:update =\> ‘live\_now\_list’,  
:frequency =\> 10 %\>

/But/ I did notice that when I moved the periodically\_call\_remote call  
to the index.rhtml which contains the partial \_live\_now.rhtml, the  
problem does not happen. When I moved it to index.rhtml the CPU stays  
low and the call works fine every 10 seconds.

It’s great that it works but I would like to understand as to why  
moving the remote call to index.rhtml fixes the problem?

Any insights would be greatly appreciated.

Cheers,  
Diego

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [March 17, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094/2 "2007-03-17T16:33:20Z")

</div>

If you are using WEBrick in development mode it is probably checking  
the partial for updates and reprocessing it, while having it in the  
rhtml it is only processed once when the page is loaded.

Michael

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [March 18, 2007, 5:44am UTC](https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094/3 "2007-03-18T05:44:40Z")

</div>

Hi Michael,

Thanks for the reply and explaining why this is happening. Even though  
I’d gotten rid of it, it’s good to know why it was happening. Is there  
a way that this can be done while running webrick in development mode  
and not have this happen? Or, if I’m using webrick in development  
mode, it’s just a matter of putting th remote call outside the partial  
and just avoiding this problem?

Thanks.

Diego

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [March 18, 2007, 11:44pm UTC](https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094/4 "2007-03-18T23:44:27Z")

</div>

You can completely avoid the problem by not putting the  
#periodically\_call\_remote method in a partial that gets reloaded a  
lot. As you discovered, each reload creates another instance of the  
javascript function.

Put it in the main page outside the partial.

cr

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [March 19, 2007, 2:59am UTC](https://www.ruby-forum.com/t/periodically-call-remote-eating-up-lots-of-cpu/89094/5 "2007-03-19T02:59:42Z")

</div>

Thanks CR. Appreciate your input.
