# Laopt is faster than server

**URL:** <https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405>\
**Category:** Deployment\
**Created:** [January 10, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405 "2009-01-10T20:09:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 10, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405/1 "2009-01-10T20:09:28Z")

</div>

I’m running the same app with the same database. In development (my  
laptop which has 2GB of RAM running Debian):

Cache write (will save 32.97ms): Product.count  
Rendered shared/\_search (36.8ms)  
Rendered shared/\_footer (0.5ms)  
Completed in 153ms (View: 72, DB: 44) | 200 OK  
[[http://localhost/products](http://localhost/products)]

Seems decent…

In production, I’m on Ubuntu (Xen Slice) with 512MB of RAM:

Rendering template within layouts/products  
Rendering products/index  
Completed in 25837ms (View: 109, DB: 25717) | 200 OK  
[[http://www.foo.com/products](http://www.foo.com/products)]

The difference in completed time (153mx vs 25837ms) is staggering to me.  
Can anyone give me a hint as to where to look for problems? I just  
can’t imagine that the ram alone is making that much of difference…

For kicks I ran the server in development mode (webrick) and got this:  
Rendering template within layouts/products  
Rendering products/index  
Completed in 17956ms (View: 257, DB: 17629) | 200 OK  
[[http://foo.com/products](http://foo.com/products)]

Which is still pretty slow. Is there a tweak I might need to make to  
MySQL on the server? Else what could explain the huge difference in  
speeds?

Thanks in advance…

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 11, 2009, 6:35pm UTC](https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405/2 "2009-01-11T18:35:14Z")

</div>

Vince W. wrote:

> Which is still pretty slow. Is there a tweak I might need to make to  
> MySQL on the server? Else what could explain the huge difference in  
> speeds?
> 
> Thanks in advance…

is there size difference between you development and production  
databases? how many rows does table ‘products’ contain in production db?

what technology is used in your production server to dispatch request to  
your ruby application (i mean, cgi or fastcgi or some advanced stuff  
like Passenger or something)?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 11, 2009, 6:45pm UTC](https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405/3 "2009-01-11T18:45:50Z")

</div>

Anton Anykeyev wrote:

> is there size difference between you development and production  
> databases? how many rows does table ‘products’ contain in production db?
> 
> what technology is used in your production server to dispatch request to  
> your ruby application (i mean, cgi or fastcgi or some advanced stuff  
> like Passenger or something)?

They are the identical db’s… about 97000 records. On the development  
side I’m using mongrel and in production I have Apache + Passenger.

To experiment I also set up a slice with 768 MB of RAM using lighttpd +  
fastcgi. Results are about the same:  
Rendering template within layouts/products  
Rendering products/index  
Completed in 23.66300 (0 reqs/sec) | Rendering: 0.11429 (0%) | DB:  
23.40731 (98%) | 200 OK [[Foo.com](http://archive.foo.com/products)]

I checked the my.cnf files on my development and deployment setups and  
they were identical. Increasing the query\_cache\_limit and  
query\_cache\_size on the server helped a bit… the first page load is  
still very slow, but subsequent (immediate) loads are faster.

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 11, 2009, 7:10pm UTC](https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405/4 "2009-01-11T19:10:54Z")

</div>

Vince W. wrote:

> Anton Anykeyev wrote:
> 
> > is there size difference between you development and production  
> > databases? how many rows does table ‘products’ contain in production db?
> > 
> > what technology is used in your production server to dispatch request to  
> > your ruby application (i mean, cgi or fastcgi or some advanced stuff  
> > like Passenger or something)?
> 
> They are the identical db’s… about 97000 records. On the development  
> side I’m using mongrel and in production I have Apache + Passenger.

i suspect that you have an index on some field in development database,  
but not in production. Maybe a table w/o primary key, maybe some  
missed-in-action migration or something. You should check metadata.  
Dunno exactly how to perform this in MySQL, afaik MySql 5 and higher  
contain INFORMATION\_SCHEMA tables.

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 12, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/laopt-is-faster-than-server/157405/5 "2009-01-12T13:35:59Z")

</div>

Vince W. wrote:

> I’m running the same app with the same database. In development (my  
> laptop which has 2GB of RAM running Debian):
> 
> Cache write (will save 32.97ms): Product.count  
> Rendered shared/\_search (36.8ms)  
> Rendered shared/\_footer (0.5ms)  
> Completed in 153ms (View: 72, DB: 44) | 200 OK  
> [[http://localhost/products](http://localhost/products)]
> 
> Seems decent…
> 
> In production, I’m on Ubuntu (Xen Slice) with 512MB of RAM:
> 
> Rendering template within layouts/products  
> Rendering products/index  
> Completed in 25837ms (View: 109, DB: 25717) | 200 OK  
> [[http://www.foo.com/products](http://www.foo.com/products)]
> 
> The difference in completed time (153mx vs 25837ms) is staggering to me.  
> Can anyone give me a hint as to where to look for problems? I just  
> can’t imagine that the ram alone is making that much of difference…
> 
> For kicks I ran the server in development mode (webrick) and got this:  
> Rendering template within layouts/products  
> Rendering products/index  
> Completed in 17956ms (View: 257, DB: 17629) | 200 OK  
> [[http://foo.com/products](http://foo.com/products)]
> 
> Which is still pretty slow. Is there a tweak I might need to make to  
> MySQL on the server? Else what could explain the huge difference in  
> speeds?
> 
> Thanks in advance…

This looks strange.

RAM could be the problem on liunux box. You have 512M, but how much is  
really available to be used? Try top command to find how much of 512M is  
really available for your application.

Option 2 is run the app in production on your desktop and then compare  
the production logs on your desktop with the one on Linux box. rawk  
([Ruby on Rails Log Analyzer – RAWK | Dogpatch Happenings](http://ckhsponge.wordpress.com/2006/10/11/ruby-on-rails-log-analyzer-rawk/))  
should be helpful to analyze quickly

regards,  
Ashutosh
