I'm experimenting with "async rails", in order to help ease the pain of using slow 3rd-party services.
Gemfile
gem 'eventmachine'
gem 'rack-fiber_pool', :require => 'rack/fiber_pool'
gem 'em-synchrony', :require => ['em-synchrony',
'em-synchrony/em-http',
'em-synchrony/activerecord']
config.ru
require ::File.expand_path('../config/environment', __FILE__)
use Rack::FiberPool, :size => 6
run MyApp::Application
Does anyone know how many Ruby Fibers can be used on Heroku's Cedar stack? Or how to go about determining such a thing?
Like you, I am currently experimenting with ruby and fibers to increase app performance. And from what I have read and think to remember, there should be almost no limit to the amount of fibers you can use.
I think to remember (please check that yourself), that each dyno can use up to 500 Mb of RAM. Each fiber adds a few kb (I think 2kb) to the RAM usage of your app. As long as your app does not use the full 500Mb, you should be fine even with 1000 fibers.
But you should hit a performance / concurrency boundary before, as your app still processes only one fiber at a time. In your case, it will depend on the external service.
Related
I have been struggling with rerunning my apps from MAC OS to my windows OS. I have never liked databases. Anyway, the thing is that I cannot even load up my seeds. It looks like it cannot run the pg gem methods. Here's my error
:in `ensure in run': undefined method `close' for nil:NilClass (NoMethodError)
here's the code the method gets stuck on
require_relative('../models/collection')
require_relative('../models/product')
require('pry')
Product.delete_all()
Collection.delete_all()
fw2015 = Collection.new({
'name' => 'Fall Winter 2015/2016'
})
fw2015.add()
I am pretty sure that it's something with postgres. Thank you for your help
This is a gem issue, not a PostgreSQL issue. It is probably relating to the fact that there are binary portions of the gem and they may not be building right. So you need to make sure that you have the PostgreSQL client libraries and header files installed, and that you have all necessary compilers.
Try uninstalling and re-installing the gem and see what errors and warnings show up.
I'm trying to set up the sinatra-authentication gem in a simple sinatra app, and running into an issue where sinatra can't find the correct views. I understand that sinatra-authentication uses haml by default, but I'm using erb in this app.
This in mind, I found in the sinatra-authenticaiton docs that there is a setting which allows you to change the template engine, by adding the following to your app file:
configure do
set :template_engine, :erb # for example
end
I've added this to my app.rb file, and sinatra is still looking for the signup.haml when I try to hit the /signup route in my app.
A couple of notes:
I've included the gem in my Gemfile, and successfuly run a bundle install on my app.
source 'https://rubygems.org'
gem 'sinatra'
gem 'data_mapper'
gem 'pg'
gem 'dm-postgres-adapter'
gem 'sinatra-authentication'
I saw something in the documentation that suggested that I may need to specify the location of my view files, so I added the following to my configuration block.
set :sinatra_authentication_view_path, Pathname(__FILE__).dirname.expand_path + "views/"
**I think I've required the gem accurately in my app file by adding
require "sinatra-authentication"
use Rack::Session::Cookie, :secret => 'mys3cr3tk3y'
This gist is a current representation of my app.rb file in the root of my sinatra app. https://gist.github.com/rriggin/5378641#file-gistfile1-txt
Here is a screenshot of the error sinatra throws: http://cl.ly/image/0y041t0K3u3O
When I run the app locally, a 'dm-users' table is created in my local db as expected.
Is there another configuration setting that I'm missing in order to get sinatra-authentication to properly look for the erb templates rather than haml files. Any help would be greatly appreciated.
Thanks
The specs don't test that the template_engine setting works, and looking at the way the setting is called, I believe it's not correct, i.e.
send settings.template_engine, get_view_as_string("index.#{settings.template_engine}"), :layout => use_layout?
might better work as:
send app.settings.template_engine, get_view_as_string("index.#{app.settings.template_engine}"), :layout => use_layout?
that's what I reckon. If you fork the project, change the line and add it to your Gemfile and it works then consider writing a quick spec for it and you'll have improved the mainline of that project as well as fixed your problem.
I've got 3 Rails 3.2 applications using the gem jquery-ui-themes. jquery-ui-themes uses scss for the image-path helper.
It works great on two of my applications, but the 3rd doesn't seem to compile the scss files in either development or production modes.
IOW, it sends this to the browser
background: #fcfdfd url(image-path("jquery-ui/redmond/ui-bg_inset-hard_100_fcfdfd_1x100.png")) 50% bottom repeat-x;
whereas the two working apps properly send
background: #fcfdfd url("/assets/jquery-ui/redmond/ui-bg_inset-hard_100_fcfdfd_1x100.png") 50% bottom repeat-x;
I've spent many hours trying to make the app that's broken as similar to possible to the two working apps as I can, but it's still failing.
My theory is that SASS is choking on something previous to redmond.css.scss. If so, there should be an error logged somewhere. Where do I find the error output from SASS?
Update:
I introduced a deliberate error into redmond.css.scss and I got a proper error dump. So I know that I'm correctly clearing the cache and actually running sass. Now to figure out why it's ignoring the image-path directives.
If you're looking for the answer to the question in the title, the answer is "the same way you get any other errors: they're in your log". To get a full backtrace, just point your browser at the asset: ie http://localhost:3000/assets/jquery-ui/redmond.css in my case.
Make sure you clear all your caches: rm -rf .sass-cache/ && rm -rf public/assets && rake tmp:cache:clear, as well as using ctrl-shift-r in your browser.
If you're looking for the answer for my real problem (image-path not working), make sure you have the proper Bundler.require line in your application.rb. The old Rails 3.0 doesn't work.
replace:
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
with:
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
I must use RightAWS for certain things. However, I can only get Paperclip uploads to S3 working when RightAWS is nowhere in my Gemfile. Since v2.3.11, Paperclip has used AWS-S3, switching from RightAWS.
RightAWS allows me to check the existence of an object without downloading the entire object via the head? method. It also allows me to stream massive amounts of files from a bucket in 1,000 unit chunks with its incrementally_list_bucket method. I haven't found a way to duplicate this functionality in AWS-S3. I do not have the time currently to implement this and contribute it either.
Can anyone tell me if there is a way to load both of these AWS gems in a Rails 3 project without causing Paperclip to cause the "wrong number of arguments (4 for 5) error?
Ta dahhh. Changing my Gemfile from:
gem 'aws-s3'
to:
gem 'aws-s3', :require => 'aws/s3'
fixed the problem!
I use rails 3.
In development mode I installed some gems for Testing (diff-lcs, nokogiri, rspec, webrat).
Since I did that, if I try to cap-deploy to the production server, it complains:
"Could not find diff-lcs in any of the sources (Bundler::GemNotFound)"
I don't want to install them on the server, because I don't need the testing purpose gems on the production server.
Can I put something in the Gemfile to maybe exclude them for production mode?
Or else how can I handle this?
Thank you very much for answering this questiion by a struggling beginner...
You can put those gems in their own group like this:
group :development, :test do
gem 'diff-lcs'
end
This page explains groups in more details: http://gembundler.com/groups.html