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
Jaded Burnout
Jul 10, 2004


Sil posted:

Any resources on figuring out what app/web server to use?

I've been using Unicorn on Heroku and it works fine. I'm looking into experimenting with AWS micro instances and my current plan is to use Nginx and Unicorn. Unfortunately, I haven't been able to find decent benchmarks for when to use which app server.

For instance, there are a number of tiny traffic apps that I was thinking of deploying on a single micro instance. Would something like Phusion Passenger make more sense in a situation like this? I ask because I'm reading that Phusio can handle multiple apps out of the box, whereas with Unicorn I'd need to start a new Unicorn master process for each app, as far as I understand.

Is that a big deal? Assuming you're using some sort of configuration management like Puppet or Chef it presumably doesn't make a lot of difference.

Passenger is considered more "old school" but I've no up to date reference on whether it's actually falling behind.

Adbot
ADBOT LOVES YOU

Sil
Jan 4, 2007

Arachnamus posted:

Is that a big deal? Assuming you're using some sort of configuration management like Puppet or Chef it presumably doesn't make a lot of difference.

Passenger is considered more "old school" but I've no up to date reference on whether it's actually falling behind.

That's what I'm wondering: Does it make a difference? From what I can find Unicorn is pretty much fine for MRI Rails apps and as fast/handles as many requests per second as any of the other options. I guess the only question is about performance with multiple apps running on one instance. I'll just go with Nginx/Unicorn/pg for now and worry about it later.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
It can be a big deal, especially in environment with limited RAM.

The process-per-request model used in many MRI installations use is pretty memory-hungry (processes are a lot fatter than threads) than what you get with the traditional thread-per-request model, so you can often serve more concurrent requests with the threaded model, especially if using JRuby (no GIL limiting parallelism). The somewhat COW-friendly GC found in MRI 2.0+ helps a bit, but it's still not perfect.

I'd benchmark your app with 3 different setups:

a) MRI / Unicorn with multiple processes
b) MRI / Puma with multiple threads
c) JRuby / torqbox with multiple threads

Before benchmarking, remember to warm up the JVM (10-20k requests should be fine) if using JRuby, to increase your db pool size to match the number of web threads and to set config.threadsafe! to true if on rails 3.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Sil posted:

Wait. Where did I pick up that """ """ thing? It must have been some rails tutorial book, but I could have sworn they said that's the way to do multiline strings in ruby. I see now, in IRB, that regular string literals do that just fine.

Have you been reading any python tutorials? It uses triple quotes for multiline strings.

kayakyakr
Feb 16, 2004

Kayak is true

Sil posted:

Any resources on figuring out what app/web server to use?

I've been using Unicorn on Heroku and it works fine. I'm looking into experimenting with AWS micro instances and my current plan is to use Nginx and Unicorn. Unfortunately, I haven't been able to find decent benchmarks for when to use which app server.

For instance, there are a number of tiny traffic apps that I was thinking of deploying on a single micro instance. Would something like Phusion Passenger make more sense in a situation like this? I ask because I'm reading that Phusio can handle multiple apps out of the box, whereas with Unicorn I'd need to start a new Unicorn master process for each app, as far as I understand.

Depends on what your apps need to do. Unicorn is great for small distributions, easy to set up and run, but it has issues when getting hammered because it can only handle as many requests as there are worker processes.

Puma is an evented server, so if you need to do things like run websockets or other neat things, you should consider that. I also like that the ability to run as a service is built in. Puma doesn't work as well with MRI because MRI has a blocking mutex that doesn't allow Puma to do its full multi-threaded thing.

I'm not the biggest fan of passenger's way of doing things. It's built to work with apache and running it on its own to work with nginx is less than ideal.

My current projects are using Puma + rubinius for websocket support. I don't have any benchmarks for you, though.

Also, Digital Ocean is cheaper and faster than AWS Micro.

Sil
Jan 4, 2007

kayakyakr posted:

Depends on what your apps need to do. Unicorn is great for small distributions, easy to set up and run, but it has issues when getting hammered because it can only handle as many requests as there are worker processes.

Puma is an evented server, so if you need to do things like run websockets or other neat things, you should consider that. I also like that the ability to run as a service is built in. Puma doesn't work as well with MRI because MRI has a blocking mutex that doesn't allow Puma to do its full multi-threaded thing.

I'm not the biggest fan of passenger's way of doing things. It's built to work with apache and running it on its own to work with nginx is less than ideal.

My current projects are using Puma + rubinius for websocket support. I don't have any benchmarks for you, though.

Also, Digital Ocean is cheaper and faster than AWS Micro.

My account is still eligible for AWS free tier offerings so that's why I'm playing with those while I learn vagrant/chef.

Is RDS worth using Amazon for when I want a dedicated DB server? I'm guessing it's equivalently easy to hookup a DO droplet or an EC2 instance to an RDS instance. There's just so much stuff on AWS. My current plan is Digital Ocean for the app RDS/same DO instance for the DB and S3 for storage space.

Less Fat Luke
May 23, 2003

Exciting Lemon

Sil posted:

My account is still eligible for AWS free tier offerings so that's why I'm playing with those while I learn vagrant/chef.

Is RDS worth using Amazon for when I want a dedicated DB server? I'm guessing it's equivalently easy to hookup a DO droplet or an EC2 instance to an RDS instance. There's just so much stuff on AWS. My current plan is Digital Ocean for the app RDS/same DO instance for the DB and S3 for storage space.
RDS is pretty cool if you use the automated multi-zone failover feature. That unfortunately though usually makes it expensive, so how much that's worth is up to you! You can definitely just roll your own MySQL install on an EC2 instance as well; the advantage with the RDS instance is that seamless failover in EC2 by yourself is pretty much impossible to do safely and in an automated fashion since you only control one network channel between hosts and can easily get into a split brain situation.

TL;DR if you're just learning and have free credit go for the smallest RDS with no failover and try it out.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Sil posted:

Any resources on figuring out what app/web server to use?

I've been using Unicorn on Heroku and it works fine. I'm looking into experimenting with AWS micro instances and my current plan is to use Nginx and Unicorn. Unfortunately, I haven't been able to find decent benchmarks for when to use which app server.

For instance, there are a number of tiny traffic apps that I was thinking of deploying on a single micro instance. Would something like Phusion Passenger make more sense in a situation like this? I ask because I'm reading that Phusio can handle multiple apps out of the box, whereas with Unicorn I'd need to start a new Unicorn master process for each app, as far as I understand.

Micro instances are poop from a butt. The biggest issue is that you don't have any guaranteed CPU, so if you have a lovely neighbor, you're gonna have a bad time. For multiple apps, you're going to have RAM problems too I bet.

KoRMaK
Jul 31, 2012



I'm using url_for on an object that has an :as clause in it's route. The proper helper is "myscope_mymodel_path"

code:
    resources :mymodel, :as => "myscope_mymodel"
but url_for only uses the helper path "mymodel_path" and as such my app crashes because there is no helper for that, it is actually "myscope_mymodel_path". How do I get url_for to be smarter and use the right helper? I'm using this with other objects that don't have the myscope prefix, so it needs to be dynamic.

Sil
Jan 4, 2007
tldr: Do you use Vagrant/Chef? Any tips?

Next step in the never-ending saga of me being poo poo at ops: I'm trying to use Vagrant and Chef together. Chef to plan out my deploys as well as to provision development VMs, through Vagrant, that match the target environment. Basically, my ultimate goal, is a DB box running Postgres and a Web box running rails with unicorn and nginx, hooked up together.

Unfortunately every loving tutorial on setting up a Rails machine with Vagrant and Chef seems to break at one point or another unless I use the tutorials locked cookbook, vagrant, chef versions. Berkshelf was apparently bundler for cookbooks and worked great with Vagrant up until October and then it wasn't. Somehow Vagrant minor releases broke the integration between them. Now I'm supposed to use kitchen whatever. Ok, but can I use kitchen whatever to provision a development box? No? Ish?

All I want, initially, is to run Rails, Postgres, Nginx all on one precise32 VM, but it seems that I lack the reading comprehension to turn 50 different github readme's and blog posts into a deploy/provision system.

I could just do this poo poo with a script.sh file and say 'gently caress portability!', but I'm convinced that I must be screwing the pooch in an easily fixable way. In fairness I did get it running once today(using librarian-chef as a terrible package manager), but then when I tried to apply the Vagrantfile/Cheffile combo to a fresh box it failed. Fml.

I'm guessing the tools are way overkill for my needs, but getting to easily load up a development environment that matches production(mostly) is very appealing. I was probably being naive thinking I could get going with it in a couple of days.

Pardot
Jul 25, 2001




Sil posted:

on one precise32 VM

Why would you use a 32 bit os in 2014? You can't stream postgres wal from 32bit to 64bit, so you'd be stuck with a dump/restore if you ever needed to get bigger.

Sil
Jan 4, 2007

Pardot posted:

Why would you use a 32 bit os in 2014? You can't stream postgres wal from 32bit to 64bit, so you'd be stuck with a dump/restore if you ever needed to get bigger.

Because I'm just trying to make a(17) tutorial(s) work. I tried the files with the precise64 box and they still don't work. Wiped the gemset and giving it a fresh try, maybe Vagrant was dicking my by choosing an older Chef version.

e. heeeey! The idiot was me! Which is great since that means my Chef/Vagrant setup works!

I'd just mixed up the Vagrantfile syntax between some tutorials which was screwing up everything.

Sil fucked around with this message at 19:09 on May 12, 2014

Jaded Burnout
Jul 10, 2004


KoRMaK posted:

I'm using url_for on an object that has an :as clause in it's route. The proper helper is "myscope_mymodel_path"

code:
    resources :mymodel, :as => "myscope_mymodel"
but url_for only uses the helper path "mymodel_path" and as such my app crashes because there is no helper for that, it is actually "myscope_mymodel_path". How do I get url_for to be smarter and use the right helper? I'm using this with other objects that don't have the myscope prefix, so it needs to be dynamic.

I haven't seen your system or requirements so take this as a maybe, but you might be trying to be too clever with your code.

KoRMaK
Jul 31, 2012



I wrote a module and a helper to figure this out. the Module goes on the object and enables it to respond to a method that returns it's nested route prefix. The helper figures out if it should turn that into a [:prefix, @item] array or if just @item will suffice.

Ravendas
Sep 29, 2001




Was asking about this in the web development thread, but it might be better placed here.

I'm new to web programming, though I've done years of C++ stuff on my own. I've written a dozen or so console based RPG generators and rollers that I'd like to make available on a website. I was told there was a simple way to do that, with the kind of IO I used in the exe's, and I was suggested to try Ruby and Sinatra.

I installed them both, tried out the Hello Worlds for both, and they worked fine. So I moved onto the actual problem.

Pokeyman gave me this starter code:

code:
require 'sinatra'

get '/' do
  output = IO.popen('../CCrap/RavsNameGenerator.exe').read
  [200, {'Content-Type' => 'text/plain'}, output]
end
It runs, but I can't connect to the localhost site, it just hangs, and never says I connected in the Ruby console. The executable runs though, because I can see it making a text file that it also outputs to in the folder.

Just to test that it wasn't the addition of the .txt fileout, I commented it all out and recompiled the C++ exe, though it still has the same problem. It just hangs. I use the standard cin and cout of C++. This is compiled and run on windows7.

Not sure how to fix that little bit of code to run the console stuff in a browser! Any ideas?

Sub Par
Jul 18, 2001


Dinosaur Gum
This isn't necessarily a rails question but I have a rails app on Heroku with the free tier postgres database. I have a table that is going to be populated by several RSS feeds - I consume the feeds once a day and add new URLs to this table. The url field is a string(255) and I have it indexed for uniqueness. Here's my question:

My application code does this check before inserting new items:
code:
if Feeditem.where(:url => incoming_url) == []
    <insert item>
end
This feels awkward and slow/lovely when there will be thousands of rows in there. Is there a better way to do this that I'm not thinking of? Should I hash the URL and store the hash in the same table and use the hash in the where instead?

Pardot
Jul 25, 2001




A unique index is fine. It stores it in a b+ tree so it's O(ln(n)) to determine if it's unique. The index will also be used as a regular index for selects and whatnot.

You can just try to insert and rescue duplicate violation exceptions, rather than check first. In fact, the check first really doesn't do anything because someone could have added a violating record in between the check and the insert. Which is why the rails unique validator is huge bullshit that doesn't do anything.

good jovi
Dec 11, 2000

'm pro-dickgirl, and I VOTE!

Pardot posted:

In fact, the check first really doesn't do anything because someone could have added a violating record in between the check and the insert. Which is why the rails unique validator is huge bullshit that doesn't do anything.

Don't you see, uniqueness checks are "business logic" and don't belong in the database.

Sub Par
Jul 18, 2001


Dinosaur Gum
Thanks guys. The check is in the application code (instead of just rescuing failed inserts) because prior to inserting a record I am parsing the Open Graph metadata from the URL and storing it as well, and I don't want to do that over and over again because it is slow. I have more appropriate checks on uniqueness elsewhere, this is mostly to prevent parsing OG metadata for URLs the application has already seen.

Pardot
Jul 25, 2001




Sailor_Spoon posted:

Don't you see, uniqueness checks are "business logic" and don't belong in the database.

I'm so angry about that, the loving using timestamp instead of timestamptz everywhere, and the general lowest common denominator (mysql) avoidance of powerful postgres features. The latter is getting a little better with support for hstore and json out of the box, and I did get word that maybe a patch to make timestamptz default would be accepted but :effort: and I don't use rails myself anymore much.

Sub Par
Jul 18, 2001


Dinosaur Gum
Since I'm in here I may as well ask, does anyone have a preferred method/gem for fixing mixed content warnings? The app is SSL but some of the Open Graph images I'm displaying are http:// and so I'm getting mixed content warnings. I'm pretty close to writing my own image proxy because everything I can find looks too complicated but if there's another way that would be great!

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.

Sub Par posted:

Since I'm in here I may as well ask, does anyone have a preferred method/gem for fixing mixed content warnings? The app is SSL but some of the Open Graph images I'm displaying are [url]http://[/url] and so I'm getting mixed content warnings. I'm pretty close to writing my own image proxy because everything I can find looks too complicated but if there's another way that would be great!

But doesn't Open Graph supports TLS just fine? :confused:

Sub Par
Jul 18, 2001


Dinosaur Gum

Smol posted:

But doesn't Open Graph supports TLS just fine? :confused:

I may be too dumb to know what this means. I am fetching the open graph metadata from various webpages and displaying the image specified by og:image in the application. Most of the time, this is an image like http://my-insecure-server.com/someimage.jpg and I need a way to prevent the browser from identifying this as "mixed content", so proxying it through my server like Facebook does or through some other means.

kayakyakr
Feb 16, 2004

Kayak is true

Sub Par posted:

This isn't necessarily a rails question but I have a rails app on Heroku with the free tier postgres database. I have a table that is going to be populated by several RSS feeds - I consume the feeds once a day and add new URLs to this table. The url field is a string(255) and I have it indexed for uniqueness. Here's my question:

My application code does this check before inserting new items:
code:
if Feeditem.where(:url => incoming_url) == []
    <insert item>
end
This feels awkward and slow/lovely when there will be thousands of rows in there. Is there a better way to do this that I'm not thinking of? Should I hash the URL and store the hash in the same table and use the hash in the where instead?

if you want to do this in ruby:
Ruby code:
unless FeedItem.exists?(:url => incoming_url)
  # insert item
end
Could also do

Ruby code:
FeedItem.find_or_create(:url => incoming_url) do |fi|
  fi.attributes = {}
end
and I think that would work.

Sub Par posted:

I may be too dumb to know what this means. I am fetching the open graph metadata from various webpages and displaying the image specified by og:image in the application. Most of the time, this is an image like http://my-insecure-server.com/someimage.jpg and I need a way to prevent the browser from identifying this as "mixed content", so proxying it through my server like Facebook does or through some other means.

If you can, instead of doing http://, just do //. That will allow the browser to choose whether it wants to use TLS or just regular old http.

Sub Par
Jul 18, 2001


Dinosaur Gum
Thanks a bunch, that seems to have resolved things.

Jaded Burnout
Jul 10, 2004


Ravendas posted:

code:
require 'sinatra'

get '/' do
  output = IO.popen('../CCrap/RavsNameGenerator.exe').read
  [200, {'Content-Type' => 'text/plain'}, output]
end
It runs, but I can't connect to the localhost site, it just hangs, and never says I connected in the Ruby console. The executable runs though, because I can see it making a text file that it also outputs to in the folder.

Not sure how to fix that little bit of code to run the console stuff in a browser! Any ideas?

Does your exe ever actually exit? The web server will hang until the `read` completes.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
Wouldn't be surprised if it was just a bug in ruby. IO-related stuff doesn't work properly half of the time on Windows (and even if it does, it probably has different semantics), because nobody tests MRI on Windows.

sofokles
Feb 7, 2004

Fuck this
So I've started playing with Rails, following a MOOC from UNM on Web Application Architectures.

A question that pops up, and that is seldom answered in intro stuff is - What if i regret and just want to get rid of it all ? or I want to rehearse, start fresh and do it all over.

In other words - will deleting the root and child folders and files you've created in a project be enough to clean the system from all traces, or is there some uninstall routine one should follow ?

Sorry if this is a stupid question, but those need to be asked too.

kayakyakr
Feb 16, 2004

Kayak is true

sofokles posted:

So I've started playing with Rails, following a MOOC from UNM on Web Application Architectures.

A question that pops up, and that is seldom answered in intro stuff is - What if i regret and just want to get rid of it all ? or I want to rehearse, start fresh and do it all over.

In other words - will deleting the root and child folders and files you've created in a project be enough to clean the system from all traces, or is there some uninstall routine one should follow ?

Sorry if this is a stupid question, but those need to be asked too.

It's an interpreted language, so all of what you've done resides in the project directory. Deleting the project directory deletes the application.

Unless, of course, you're working with ruby and created a few executables that were placed in your bin directories. Not a common thing to do, though.

sofokles
Feb 7, 2004

Fuck this
Thanks mate

Molten Llama
Sep 20, 2006
If you're using a "real" database (not SQLite), you'd also want to drop the DB to remove all traces.

KoRMaK
Jul 31, 2012



How do I determine the max length of a text column in Mysql via rails? I know its 65,535b but I want to figure that out dynamically incase we expand/contract that column size.

Smol
Jun 1, 2011

Stat rosa pristina nomine, nomina nuda tenemus.
If nothing else (I'm not a MySQL expert), you can parse the output of SELECT COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_NAME = 'foos' AND COLUMN_NAME = 'whatever' and look for mediumtext, longtext or whatnot.

There's also Foo.columns['whatever'].type, but I'm not sure if it differentiates between all the possible text/blob column types in mysql.

Smol fucked around with this message at 21:50 on May 21, 2014

Sub Par
Jul 18, 2001


Dinosaur Gum
Another dumb question from me! I have Post model (in a Rails 3 app) that has just a couple attributes: user_id, title, content. I have the model set up to protect against mass assignment so people can't post as other users
code:
attr_accessible :title, :content
I would like to set up a system that automatically posts system messages using an account named "ServiceAccount" or whatever with user_id of 10. In the controller, I'm building these posts like this:
code:
Post.create(:title => some_object.title, :content => some_object.title, :user_id => 10)
This obviously doesn't work. I do not want to add :user_id to attr_accessible. Is there some way to accomplish this without exposing Post model to security risks?

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Um, you can make user_id accessible and just go by current user? Then write a custom method for your system thing

Sub Par
Jul 18, 2001


Dinosaur Gum
Edit: ok I did this which seems to do what I want and keep things secure. In the model:
code:
attr_accessible :title, :content
attr_accessible :title, :content, :user_id, as: :system_post
In the method:
code:
@p = Post.new({title: some_object.title, content: some_object.content, user_id: 10}, as: :system_post)
if @p.save
   <etc>

Sub Par fucked around with this message at 17:41 on May 22, 2014

prom candy
Dec 16, 2005

Only I may dance

Sub Par posted:

Another dumb question from me! I have Post model (in a Rails 3 app) that has just a couple attributes: user_id, title, content. I have the model set up to protect against mass assignment so people can't post as other users
code:
attr_accessible :title, :content
I would like to set up a system that automatically posts system messages using an account named "ServiceAccount" or whatever with user_id of 10. In the controller, I'm building these posts like this:
code:
Post.create(:title => some_object.title, :content => some_object.title, :user_id => 10)
This obviously doesn't work. I do not want to add :user_id to attr_accessible. Is there some way to accomplish this without exposing Post model to security risks?

p = Post.new(:title => some_object.title, :content => some_object.title)
p.user_id = 10
p.save

Does that work?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
Could you make a Post.system scope that implies a user_id of 10?

prom candy
Dec 16, 2005

Only I may dance
Depending on how big this app is it might be a good idea to just upgrade to Rails 4 and use strong_params for this. It's what it was built for pretty much.

Adbot
ADBOT LOVES YOU

Sub Par
Jul 18, 2001


Dinosaur Gum

prom candy posted:

Depending on how big this app is it might be a good idea to just upgrade to Rails 4 and use strong_params for this. It's what it was built for pretty much.

Yeah that's what I wanted to do. It's not a huge app but it's something I was working on months ago while trying to learn rails, and I've just recently come back to it and I don't feel like going through all that. At this stage I have about 50 users and it's proof-of-concept level complete. Once I make it feature-complete I will probably upgrade to rails 4.

Thanks for the suggestions everyone. I'm going to try out a few different approaches and see which I like best and then just move on. Since I know this can be done more easily in rails 4 I may just ditch this feature for now and come back to it after the upgrade.

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