Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
manero
Jan 30, 2006

shopvac4christ posted:

That's what I've heard, but I haven't had a chance to actually try it. That's what I'm asking. Where are people deploying their projects? Their one-off, unimportant stuff? I'm not shelling out 400 dollars a month for an Engine Yard slice. I'm still in college, you know?

Like I said, slicehost is pretty decent.

You could also setup a machine in VMWare or whatever and treat it as a remote deployment box just to mess around with.

Adbot
ADBOT LOVES YOU

HIERARCHY OF WEEDZ
Aug 1, 2005

Oooh, a VM image is a good idea. But Slicehost is looking pretty tempting. I don't want to just run Rails apps, since I'm a Merb and Camping guy, too. I have a feeling I'll get plenty of mileage out of a VPN.

jonnii
Dec 29, 2002
god dances in the face of the jews
I use slicehost, they are awesome. Highly recommended.

savetheclocktower
Sep 23, 2004

You wait and see, Mr. Caruthers. I will be president! I'll be the most powerful president in the history of America. And I'm gonna clean up this country!

jonnii posted:

I use slicehost, they are awesome. Highly recommended.

Thirded.

savetheclocktower
Sep 23, 2004

You wait and see, Mr. Caruthers. I will be president! I'll be the most powerful president in the history of America. And I'm gonna clean up this country!

Grob posted:

No, some of us have Rails projects in production. Forumwarz, my MMO, is deployed on a dedicated host.

The technology is Nginx proxying to a pack of Mongrels.

I don't have any recommendations for small projects, but if you are doing mid-sized traffic (right now we're doing 20 dynamic rq/sec) a dedicated server is quite affordable at most hosting companies.

I just assumed that since you said you were interested in Phusion that you were working on something smaller.

Off-topic: Forumwarz is awesome. You guys do great stuff on the JavaScript side.

Hammertime
May 21, 2003
stop
I can chip in on deployment advice for medium-larger apps (no single point of failure etc.).

Main stuff I've deployed:
1. Software as a service web app that just launched ( nginx load balancers/asset servers -> apache + fcgid -> memcached + replicated mysql). Only architecture that could work for us, long story.
2. Highly dynamic(uncacheable) public site (nginx -> mongrel cluster -> memcached + oracle)

I love nginx & memcached.

I've only deployed on dedicated/larger virtual servers, so I can't really advise for smaller slice based arrangements.

Evil Trout
Nov 16, 2004

The evilest trout of them all

savetheclocktower posted:

Off-topic: Forumwarz is awesome. You guys do great stuff on the JavaScript side.

Thanks, that's mostly due to Prototype and Scriptaculous making it so easy!

Pardot
Jul 25, 2001






Oh no! It all works fine on iMacs at work – no spec failures or this out of memory stuff, but my poor old macbook just can't handle it. Probably an issue with my ruby or something, but who knows. It's kinda funny just how bad it broke.

GroceryBagHead
Nov 28, 2000

Never seen anything like that. Also you have shitloads of tests going on there. How long does it take to run and why so many?

Pardot
Jul 25, 2001




I don't think that's all of the specs, because it blew up. There are a few old tests too that are slowly being moved into tests. On the dev machines, the tests+specs take about 5-6 minutes I think. That defiantly needs to be sped up. There are also about 15 min worth of selenium tests, but usually you just let the ci box run those, except for the ones you know you're hitting. The ci box is an old mac mini, and poor thing takes like 50 min to run through the specs, tests, selenium, and javascript tests.

Why so many? It's a very large and complicated app. We have something like 10k lines of code and 35k of tests, though I don't think rake stats counts some of the stuff. Some could argue that it's overkill, but it just happens that way because of BDD.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I have a $5/month account at https://www.railsplayground.com and host 4 small applications on it. What is all this dedicated talk, shared hosting is sufficient for a blog, band website, small business website and extraneous test or staging application.

geez

Hop Pocket
Sep 23, 2003

For those of you that use autotest (you do use autotest, don't you?), Growl configuration on OS X just got quite a bit easier:

http://growl-glue.rubyforge.org/

code:
% sudo gem install growl-glue
Inside of ~/.autotest, an example configuration:

code:
require 'growl_glue'
GrowlGlue::Autotest.initialize do |config|
    config.notification :use_network_notifications => true
    config.title :success => "Love", :failure => "Hate"
    config.say :failure => "Something is horribly wrong!"
end
Hopefully this brings autotest joy to someone. It's my first gem :)

Strong Sauce
Jul 2, 2003

You know I am not really your father.





So I'm trying to get into programming 2.1 however a lot of material is either for rails 1.2/1.4 or some older version of rails. Is there a site that discusses the changes between previous version of Rails and what Rails is at the moment?

GroceryBagHead
Nov 28, 2000

Well, for general api reference http://rails-doc.org is awesome. Hopefully it will be as good as php.net one day.

There's pretty significant jump from 2.0 to 2.1 so old 1.* rails are almost irrelevant. http://weblog.rubyonrails.org/ is pretty alright if you want to follow wtf is happening (although most of the discussion is about Edge Rails that takes a bit to become stable). But for 2.1 changes check this out: http://weblog.rubyonrails.org/2008/6/10/free-rails-2-1-book

skidooer
Aug 6, 2001

Strong Sauce posted:

Is there a site that discusses the changes between previous version of Rails and what Rails is at the moment?
http://ryandaigle.com/ is probably your best bet.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA
Sup rails-goons, no idea how many of you are core wannabes, but in case the answer is 'some' - check out my request for comments for a validations refactor:

http://groups.google.com/group/rubyonrails-core/browse_thread/thread/4cce3966cd61f278

(link to github contained within)

I think it's a step in the right direction (well OBVIOUSLY - since i wrote it and whatnot) but I'm getting awfully tired of working on it and it sure would be nice to have some help, especially in the form of patches :)

Did You Know: Contributing rails patches makes you ridiculously employable, and also free blowjobs.

Pardot
Jul 25, 2001




Mr. Wynand in the linked post posted:

One thing that (IMO) causes a lot of confusion (in a general sense) is how .errors[:whatever] can sometimes return an array of strings, and sometimes just the string. NOTHING ELSE EVER DOES THIS IN RUBY. EVER

Spot on. I hope this gets merged in. I came across a thing with AR's sql generation that I may write a patch for. I wasn't sure it'd be worth it, but if you say there'll be blowjobs, than it just might be!

Carabus
Sep 30, 2002

Booya.
I have a large hash of values which is an intermediary for simpler calculations. This object needs to be stored because it takes so long to generate. I can do this with PStore but is it more advisable to use ActiveRecord, or something else? Seems a bit overkill to use relational database to store something relatively simple, but speed may be important.

manero
Jan 30, 2006

Carabus posted:

I have a large hash of values which is an intermediary for simpler calculations. This object needs to be stored because it takes so long to generate. I can do this with PStore but is it more advisable to use ActiveRecord, or something else? Seems a bit overkill to use relational database to store something relatively simple, but speed may be important.

Memcache.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Pardot posted:

Spot on. I hope this gets merged in. I came across a thing with AR's sql generation that I may write a patch for. I wasn't sure it'd be worth it, but if you say there'll be blowjobs, than it just might be!

It's surprisingly easy to get a patch included provided you include unit tests with it.

Basically you just post a ticket with the .diff file in lighthouse and then you need 3 people to review it ("+1"ing - anyone can do it - not just core peeps) which will force a core guy to look at it and include it. Depending on the severity of what you're doing this can happen over night or over a few weeks, but pretty much everything that is well tested doesn't try to do something silly (like build-in LDAP support or some poo poo, i.e. stuff that should be a plugin) makes it in eventually.

For work we have our own rails branch which includes any patches we contribute before they are actually accepted. We've gotten to the point where they are equivalent several times now (i.e. all our patches, or something equivalent, makes it to upstream).

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come
Is there a way to explicitly set the id, instead of letting it auto_increment, when creating a record with AR? I'd prefer not to do this in actual SQL, but whatever if I have to I have to.

Carabus
Sep 30, 2002

Booya.

manero posted:

Memcache.
But memcached doesn't offer persistent storage like PStore, it is designed to be used in conjunction with something like a database. At least that's my impression. Probably I should store the thing with ActiveRecord and use memcached for long iterations.

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

dustgun posted:

Is there a way to explicitly set the id, instead of letting it auto_increment, when creating a record with AR? I'd prefer not to do this in actual SQL, but whatever if I have to I have to.

I don't know of hand, but are you absolutely sure you have to?

I hate to give such a "DHH answer" but I've usually found it to be the case that no, setting the ID manually is not required.

(PS: the times where it's genuinely required usually entail hardcore scale-across-a-cluster issues, and if you're having THAT kind of problem you should probably be using your oodles of VC cash to hire a core guy)

Mrs. Wynand
Nov 23, 2002

DLT 4EVA

Carabus posted:

But memcached doesn't offer persistent storage like PStore, it is designed to be used in conjunction with something like a database. At least that's my impression. Probably I should store the thing with ActiveRecord and use memcached for long iterations.

But you just said it's an intermediary value that can be regenerated :confused:

If persistence is actually more important, just stick with AR it will probably be fast enough. If it's setting up the schema that bothers you and you're sure you won't ever need to retrieve your value by anything other then a single key (which sounds likely), dump the object in 1 column using yaml or something.

If you really truly need something that is both ridiculously fast AND persistent you can look into 'document databases' like hadoop or couchdb.

But you very very very likely don't.

Carabus
Sep 30, 2002

Booya.

Mr. Wynand posted:

But you just said it's an intermediary value that can be regenerated :confused:
Well it takes about 15 minutes to generate, and contains multiple keys (like {item1=>{item2=>0.5,item3=>0.9}, item2=>{item1=>0.5,item5=>0.2}} and so on, on and on). But you're right ActiveRecord will probably do fine and likely easier to manage and manipulate in the long term. The schema is a bit daunting, however. I'm considering a different approach which will not rely on such an enormous object.

dustgun
Jun 20, 2004

And then the doorbell would ring and the next santa would come

Mr. Wynand posted:

I don't know of hand, but are you absolutely sure you have to?
I don't, but it's something I want to do to keep things cleaner in the future. Basically, I'm normalizing a table ("files") a bit so that I can trim down that table, and then join the specific type ("images", "movies", etc..) with it to get the general details. So like now you can do /movies/:id or /images/:id and it just looks up the info in 'files', but I want to have it do the lookup in 'movies' or 'images' against the id, not file_id. That way 'movies' and 'images' will increment independently of one another from now on, but existing ids will remain the same.

Crap, that's a horrible explaination. Eitherway, it's something I started doing and then sort of wondered if you could do it with AR :)

skidooer
Aug 6, 2001

Mr. Wynand posted:

hire a core guy
I don't think you need a core guy for something so simple. ;)

code:
class Foo < ActiveRecord::Base
  before_create :set_id
  
  def set_id
    self.id = rand(9999)
  end
end

Unixmonkey
Jul 3, 2002

skidooer posted:

I don't think you need a core guy for something so simple. ;)

code:
class Foo < ActiveRecord::Base
  before_create :set_id
  
  def set_id
    self.id = rand(9999)
  end
end

This is bad because eventually it will randomize to an existing id and go boom.

code:
class Foo < ActiveRecord::Base
  before_create :set_id
  
  def set_id
    identifier = rand(9999)
    until Foo.find_by_id(identifier).nil?
      identifier = rand(9999)  
    end
    self.id = identifier
  end
end
Untested, but you get the idea. If an existing record has the id you generated, it generates a new one until it finds one that doesn't match. When you get close to 9,999 records, this will become expensive to run while the system searches for unused id's.

Concurrency may not be a problem in your app, but this also opens it up for a race condition where you check for an id and not find it and try to set the id, but another process used up that id in the split second before you save. (more likely when the pool of available ids grows slim) I'm not saying it wrong to do something like this (I do something similar in one of my apps), but there are reasons why auto-incrementing id's are good.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Lets say I have about 20 tables that include more or less each a set of options for 20 different select boxes. These will change rarely, I have set up all the functionality required to display these select boxes and show the user's selected options somewhere all over a page someplace.

What is the best way to ensure there aren't 20 hits to the database on every edit request and a further 20 hits to the database on every page view where these results are displayed?

I can use page caching where the results are displayed but I am a bit dumbfounded by the idea of caching the select boxes that allow the users to change these settings as they need to be pre-populated with the values the user has selected.

Is the best way to just page cache on the edit page as well? Because the chances are that any time a user visits the edit page, they will be changing something that will clear the cache anyways.

Nolgthorn fucked around with this message at 09:39 on Jul 18, 2008

Evil Trout
Nov 16, 2004

The evilest trout of them all

Nolgthorn posted:

Lets say I have about 20 tables that include more or less each a set of options for 20 different select boxes. These will change rarely, I have set up all the functionality required to display these select boxes and show the user's selected options somewhere all over a page someplace.

What is the best way to ensure there aren't 20 hits to the database on every edit request and a further 20 hits to the database on every page view where these results are displayed?

I can use page caching where the results are displayed but I am a bit dumbfounded by the idea of caching the select boxes that allow the users to change these settings as they need to be pre-populated with the values the user has selected.

Is the best way to just page cache on the edit page as well? Because the chances are that any time a user visits the edit page, they will be changing something that will clear the cache anyways.

In your controller, cache the results from the database calls.

If you're on Rails 2.1, caching is pretty easy to set up with a variety of stores (I can't recommend Memcached enough.)

http://www.thewebfellas.com/blog/2008/6/9/rails-2-1-now-with-better-integrated-caching

Tziko
Feb 18, 2001

GroceryBagHead posted:

Well, for general api reference http://rails-doc.org is awesome. Hopefully it will be as good as php.net one day.
Just a heads-up: Rails-doc 2.0 was released today. The update includes multiple improvements, including documentation for the different versions of Rails. Hopefully it'll shape up to be the php.net of Rails...

Pardot
Jul 25, 2001




Tziko posted:

Just a heads-up: Rails-doc 2.0 was released today. The update includes multiple improvements, including documentation for the different versions of Rails. Hopefully it'll shape up to be the php.net of Rails...

Hooray, I asked them for hi res icons to use with Fluid, and they did http://rails-doc.org/about

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.
Two dirt-simple Ruby questions:

1) Let's say that I have a string that's "ENTRY9_blahblah". I need to pull out that 9 as an integer. There must be a better way to do this than either
code:
str.unpack("xxxxxa").to_s.to_i
or
code:
str[5] - 48
but because I'm stupid I have no idea what that way is.

2) I have a bunch of numbers stored as fixed-width strings in hex. For example, I'll have "12345678abcdef01" which I want to extract as 1 number with a value of 0x12345689, 1 number with a value of 0xabcd and 1 more number with a value of 0xef01. Currently I'm doing this:
code:
first_num = str[0..7].to_i(16)
second_num = str[8..11].to_i(16)
third_num = str[12..15].to_i(16)
But again, that seems really stupid. There must be a correct way to do this, right?

Hop Pocket
Sep 23, 2003

Plastic Jesus posted:

Two dirt-simple Ruby questions:

1) Let's say that I have a string that's "ENTRY9_blahblah". I need to pull out that 9 as an integer. There must be a better way to do this than either
code:
str.unpack("xxxxxa").to_s.to_i
or
code:
str[5] - 48

(/ENTRY(.*?)_.*/.match(str))[1].to_i

code:
>> str = "ENTRY9_blah"
=> "ENTRY9_blah"
>> (/ENTRY(.*?)_.*/.match(str))[1].to_i
=> 9
>> 
There might be a simpler shorthand for regexes, but you would want to use a regex instead of unpack to do this.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

Hop Pocket posted:

There might be a simpler shorthand for regexes, but you would want to use a regex instead of unpack to do this.

Cool, thanks. I would probably do
code:
(/ENTRY(\d?)/.match(str))[1].to_i
Is there an easy way to find out in irb which method is faster in these situations? I'd like to know that the performance difference is for regex v. unpack v. anything else. And while we're on the subject, does Ruby use the old-style (and much faster) Bell Labs DFA regex algorithm or the weird (and slower) perl-style algorithm?

drjrock_obgyn
Oct 11, 2003

once i started putting pebbles in her vagina, there was no going back

Plastic Jesus posted:

Is there an easy way to find out in irb which method is faster in these situations? I'd like to know that the performance difference is for regex v. unpack v. anything else. And while we're on the subject, does Ruby use the old-style (and much faster) Bell Labs DFA regex algorithm or the weird (and slower) perl-style algorithm?

code:
require 'benchmark'

str = "ENTRY9_blahblah"
repeating = 50000

Benchmark.bm(19) do |t|
  t.report('regex: /ENTRY(\d+)/') do
    repeating.times { (/ENTRY(\d+)/.match(str))[1].to_i }
  end

  t.report('regex: /ENTRY(\d?)/') do
    repeating.times { (/ENTRY(\d?)/.match(str))[1].to_i }
  end

  t.report('regex: /Y(\d{1,})/') do
    repeating.times { (/Y(\d{1,})/.match(str))[1].to_i }
  end

  t.report('unpack:') do
    repeating.times { str.unpack("xxxxxa").to_s.to_i }
  end
end
Gives me this:

code:
                         user     system      total        real
regex: /ENTRY(\d+)/  0.140000   0.000000   0.140000 (  0.141113)
regex: /ENTRY(\d?)/  0.130000   0.000000   0.130000 (  0.137405)
regex: /Y(\d{1,})/   0.140000   0.000000   0.140000 (  0.142925)
unpack:              0.110000   0.000000   0.110000 (  0.105741)
So unpack might be the fastest, but marginally. I'd use the regex for readability.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

drjrock_obgyn posted:

So unpack might be the fastest, but marginally. I'd use the regex for readability.

Hrm, interesting. I'd not played with benchmark before. I found out that my ugly-looking current approaches are actually the fastest by a long shot:

code:
[twitch@varial]$ cat ./b.rb
#!/usr/bin/ruby 

require 'benchmark'
include Benchmark

reps = 50000
str = "ENTRY9_laalalala"
str2 = "12345678abcdef01"
bm(20) do |x|
    x.report('Slice-and-subtract') {
        reps.times { a = str[5] - 48 }
    }

    x.report('Regex') {
        reps.times { a = str.match(/ENTRY(\d)/)[1].to_i }
    }

    x.report('Array ranges') {
        reps.times {
            a = str2[0..7].to_i(16)
            b = str2[8..11].to_i(16)
            c = str2[12..15].to_i(16)
        }
    }

    x.report('Unpack') {
        reps.times {
            a = str2.unpack("aaaaaaaa").join.to_i(16)
            b = str2.unpack("xxxxxxxxaaaa").join.to_i(16)
            c = str2.unpack("xxxxxxxxxxxxaaaa").join.to_i(16)
        }
    }
end

[twitch@varial]$ ./b.rb
                          user     system      total        real
Slice-and-subtract    0.050000   0.000000   0.050000 (  0.052927)
Regex                 0.160000   0.000000   0.160000 (  0.165503)
Array ranges          0.250000   0.000000   0.250000 (  0.257308)
Unpack                0.690000   0.000000   0.690000 (  0.709527)
Edit: Thanks, updated to reflect multiple runs
VVVVVVVVVVVVVVVVVVVVVVVVVV

Plastic Jesus fucked around with this message at 19:12 on Jul 20, 2008

skidooer
Aug 6, 2001

Plastic Jesus posted:

I found out that my ugly-looking current approaches are actually the fastest by a long shot:
It looks like you forgot to run the operation several times. You'll want to do that when benchmarking.

skidooer fucked around with this message at 16:58 on Jul 20, 2008

Evil Trout
Nov 16, 2004

The evilest trout of them all
In case anyone is interested, I just released Kawaii, which is kind of like a script/console web-front end for those of you like me who hang out in a console all day while developing in Rails.

It's open source, hosted at Github. Any feedback would be appreciated!

Adbot
ADBOT LOVES YOU

bitprophet
Jul 22, 2004
Taco Defender
So, um. Why would I want to use Kawaii instead of, you know. A terminal window? :psyduck: This reminds me of Campfire's reinvention of IRC because "it wasn't a Web site" (and then of course a client-side app, Pyro, to interface with the Web site, making it even more :psyduck:...)

That said, I'm sure it was fun to make, and it looks neat, so good job at any rate!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply