Rails & Heroku: How many workers/dynos do I need
Not sure you're asking the right question. Your real question is "how can I get better performance?" Not "how many dynos?" Just adding dynos won't necessarily give you better performance. More dynos give you more memory...so if your app is running slowly because you're running out of available memory (i.e. you're running on swap), then more dynos could be the answer. If those jobs take 10 seconds each to run, though...memory probably isn't your actual problem. If you want to monitor your memory usage, check out a visualization tool like New Relic.
There are a lot of approaches to solving your problem. But I would start with the code that your wrote. Posting some code on SO might help understand why that job takes 10 seconds (Post some code!). 10 seconds is a long time. So optimizing the queries inside that job would almost surely help.
Another piece of low hanging fruit...switch from resque to sidekiq for your background jobs. Really easy to use. You'll use less memory and should see an instant bump in performance.
what is the tradeoff between using larger dynos vs more dynos on Heroku
As far as I know as you already mentioned Heroku routers don't know and care about load in a specific dyno and sends the request by a random selection algorithm. https://devcenter.heroku.com/articles/http-routing
So it is very likely to see many consecutive requests going to same dyno. I am observing that behaviour with my current applications.
But in your case if a worker need 230MB then you can't use 2 worker in a Standard-1X dyno because their max memory is 512M. So I think you should definitely go for 2X dynos with like 3-4 workers. 2X dynos can use up to 1GB memory.
What is the difference between four 1X dynos and two 2X dynos in heroku?
More dynos give you more concurrency. Based on a single threaded web server such as thin, if you have 4 x 1x dynos, you can serve four requests at the same time.
With 2 x 2x dynos you can only serve two requests.
2x dynos have more memory (1024MB) and more CPU available. This is useful if your application takes up a lot of memory. Most apps should not need 2x dynos.
Heroku have recently added PX dynos as well, which have significantly more power available.
You can read about the different dynos Heroku offers on their website.
Heroku: How to open rails api dyno on port 3001
From the Heroku Procfile docs:
The
web
process type is special as it’s the only process type that will receive HTTP traffic from Heroku’s routers. Other process types can be named arbitrarily.
If you want to have multiple HTTP applications running, you’re going to have to accomplish that a different way, as you can’t have more than one HTTP process type in an app. One option would be to run a completely separate Heroku app for the other HTTP app.
Related Topics
Read Input from Console in Ruby
When to Use Struct Instead of Hash in Ruby
Installing Ruby 1.9.1 on Ubuntu
Ruby: Is There an Opposite of Include? for Ruby Arrays
When We Import CSV Data, How Eliminate "Invalid Byte Sequence in Utf-8"
Cannot Access Local Sinatra Server from Another Computer on Same Network
Ruby Convert Array into Function Arguments
How to Run Shell Commands on Server in Capistrano V3
Rails: Good Rspec2 Example Usage? (Also: Cucumber, Pickle, Capybara)
Ruby Method Calls Declared in Class Body
Extract Links (Urls), with Nokogiri in Ruby, from a Href HTML Tags
Mongodb with Mongoid in Rails - Geospatial Indexing
Cannot Click HTML Element with Watir
Manually Retry Job in Delayed_Job
How to Run Ruby on Rails with Ruby 1.9X
Remove Substring from the String
How to Write Negative Loop in Ruby Like For(I=Index; I >= 0; I --)