我想知道上传中等大小文件的一般共识是什么.我有一个Web应用程序,每次用户上传文件(通常大于5mb)时,Web服务器都会挂起,直到文件上传完成.
以上看似乎很正常,因为单个上传可以占用单个HTTP请求处理程序.网络开发人员是否考虑到这一点,并且:
a)支付更多HTTP处理程序
b)使用其他方法通过使用AJAX或其他方法来克服这个问题
我听说网络应用程序有一些HTTP请求处理程序来处理这个问题是很正常的,这将花费更多.另一方面,如果成本是一个问题,那么有些人建议尝试直接通过Flash + AJAX直接上传到Web服务器或存储服务(即Amazon S3).后一种方法需要一些脚本,并且有点混乱.
我的第二个问题:
通过使用ajax将文件上载到服务器上.这仍然占用整个HTTP请求处理程序吗?即服务器是否挂起,直到上传完成?
即使使用闪存,我仍然需要指定要上传的网址.该url将是我的控制器上的操作之一.这意味着处理仍然发生在服务器端.到目前为止这是对的吗?
我刚在想.另一方面,如果我使用其中一个上传脚本(plupload,uploadify,swfupload等)直接上传到Amazon S3,则处理将在S3服务器而不是本地Web服务器上处理.哪个不会挂起网络应用程序.我理解正确吗?
想听听您的反馈意见.
我们使用Amazon S3和CDN.我们的应用程序在Heroku上运行.我们正在考虑使用像RDS或Xeround这样的DBaaS.
因为我们已经在使用亚马逊的S3和CDN,我们应该使用RDS吗?由于所有技术都在同一主机(亚马逊)上运行,是否会有任何性能提升,而不是使用第三方(Xeround)的东西?
或者它应该没关系?
在Rails 3.0.X中,这条线用于工作:
email_banner = File.read(Rails.root.join('public/images/email_banner.png'))
Run Code Online (Sandbox Code Playgroud)
由于Rails 3.1 RC将图像dir移动到app/assets/images,我得到错误:
Errno::ENOENT: No such file or directory - /Users/Foo/Sites/foobar/public/images/email_banner.png
Run Code Online (Sandbox Code Playgroud)
我如何在Rails 3.1 RC中使用它?
供您参考,我的UserMailer类的代码块:
class UserMailer < ActionMailer::Base
default :from => "from@example.com"
def verification_email(user_id)
@user = User.find(user_id)
@verification_url = verification_url(:id => @user.verification_code)
email_banner = File.read(Rails.root.join('public/images/email_banner.png'))
attachments.inline['email_banner.png'] = email_banner
mail(:from => "Foobar <support@foobar.com>",
:to => "#{@user.full_name} <#{@user.email}>",
:subject => 'Foobar Verification Email')
end
....
Run Code Online (Sandbox Code Playgroud)
我可以使用asset_path吗?
select_tag :country_id, options_from_collection_for_select(Country.order('priority desc, name asc'), "id", "name"), { :prompt => 'Select a country', :include_blank => 'None' } %>
Run Code Online (Sandbox Code Playgroud)
如预期的那样,除了:include_blank => 'None'.呈现空白选项.像这样:
<option value=""></option>
Run Code Online (Sandbox Code Playgroud)
第二,与select_tag.如何指定默认值.例如,如果我需要选择框来选择特定国家/地区.我尝试添加:selected => Country.first无济于事:
<%= select_tag :country_id, options_from_collection_for_select(Country.order('priority desc, name asc'), "id", "name"), { :prompt => 'Select` a country', :include_blank => 'None', :selected => Country.first } %>
Run Code Online (Sandbox Code Playgroud)
以上始终选择"选择国家/地区".
为什么?
将对象传递给Resque作业是否安全?例如:
Resque.enqueue(Foobar, @foo, @bar)
Run Code Online (Sandbox Code Playgroud)
代替:
Resque.enqueue(Foobar, @foo.id, @bar.id)
Run Code Online (Sandbox Code Playgroud)
如果我传递对象,有什么不利之处吗?
在Heroku上使用Unicorn时.扩展,将会有问题,因为当它仍然加载应用程序时,请求可以访问新缩放的web dyno.这主要导致超时错误.
我在http://codelevy.com/2010/02/09/getting-started-with-unicorn.html和https://github.com/blog/517-unicorn上做了一些阅读
这两篇文章建议使用preload_app true.和after_fork和before_fork块.
在Rails 3+中,before_block仍然需要代码吗?我读到了某个地方,否则.任何经历过这种情况并且想要分享的人?
我错过了什么吗?我是否正确加载了应用程序?
# config/initializers/unicorn.rb
# Read from:
# http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/
worker_processes 3 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 90 seconds
# Noted from http://codelevy.com/2010/02/09/getting-started-with-unicorn.html
# and https://github.com/blog/517-unicorn
preload_app true
after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end
before_fork do |server, worker|
##
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and …Run Code Online (Sandbox Code Playgroud) 有没有request.remote_ip或request.ip可以返回的情况nil?
我一直在考虑设置适当的池大小(在database.yml中).
我在database.yml中使用了pool选项时遇到了类似的问题,但需要进一步了解这一点.
这是我的设置.我有运行Unicorn的实例有5个工作进程'.我也有Sidekiq实例,并发设置为5(我认为这是5个并发线程).
我的游泳池大小应该考虑什么?我应该考虑哪些其他因素?
这是我到目前为止的理解(引自我之前与之交谈过的工程师):
假设您将其保留为默认值5.这只是意味着,在"单个进程"中,池大小为5.池是每个进程.它不是系统范围的,因此值为5并不意味着您只限于5个进程,这意味着每个 进程都有自己的池,大小为5.
总之,每个实例的数据库池大小为5.这也意味着数据库池大小设置不是应用程序范围,而是每个进程/实例.这也意味着,因为Sidekiq和Unicorn将在自己的实例中运行.它将拥有自己的db池大小为5.这个假设是否正确?
此时,我可以假设默认池大小为5通常是安全的.你的意见?
PS.如果您可以共享AWS RDS实例的池大小.那将是值得赞赏的.
我有以下迁移:
class CreateFoos < ActiveRecord::Migration
def change
create_table :foos do |t|
t.hstore :foos_properties
end
end
end
Run Code Online (Sandbox Code Playgroud)
在hstore列中,我有2个键::foo和:bar.是否可以创建另一个要删除的迁移:foo?应该怎么样?
我发现了这个:
Foo.update_all([%(foos_properties = delete("foos_properties",?)), 'foo'])
Run Code Online (Sandbox Code Playgroud)
这样安全吗?或者我应该考虑一种更明智的方法?
migration postgresql activerecord ruby-on-rails ruby-on-rails-4
在rails迁移中.如何将字符串类型列更改为bigint?
我有:
t.change :ip_number_from, :integer, :limit => 8
Run Code Online (Sandbox Code Playgroud)
我明白了:
PG::Error: ERROR: column "ip_number_from" cannot be cast to type bigint
Run Code Online (Sandbox Code Playgroud)
我甚至尝试过两种选择:
change_column :ip_to_countries, :ip_number_from, :integer, :limit => 8
change_column :ip_to_countries, :ip_number_from, :bigint
Run Code Online (Sandbox Code Playgroud)
还是一样的错误.
postgresql ×3
database ×2
heroku ×2
migration ×2
actionmailer ×1
activerecord ×1
amazon-rds ×1
forms ×1
javascript ×1
resque ×1
unicorn ×1
xeround ×1