- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我在 heroku 上托管的 ruby on rails
应用程序经常收到此错误 Memory quota exceeded
:
2014-12-29 11:09:37.876 355 <45>1 2014-12-29T11:09:37.210533+00:00 heroku worker.1 - - source=worker.1 dyno=heroku.22144543.00c11b4d-8ec6-46d9-addf-f03163e10f0c sample#memory_total=2899.25MB sample#memory_rss=1023.73MB sample#memory_cache=0.00MB sample#memory_swap=1875.52MB sample#memory_pgpgin=2603236pages sample#memory_pgpgout=2341160pages
2014-12-29 11:09:37.876 132 <4
2014-12-29 11:09:37.876 132 <455>1 2014-12-29T11:09:37.210533+00:00 heroku worker.1 - - Process running mem=2899M(283.1%)>1 2014-12-29T11:09:37.210533+00:00 heroku worker.1 - - Error R14 (Memory quota exceeded)
我阅读了建议 solution 的博客即设置 WEB_CONCURRENCY
配置变量,但我不清楚。
我目前在 heroku 上的配置是:
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 29
preload_app true
已编辑:
worker 代码
class PhotoWorker
include Sidekiq::Worker
sidekiq_options queue: "high"
# sidekiq_options retry: false
def perform(params)
begin
puts "Start Woker for #{params.inspect}"
site = Site.find params['site_id']
if params["id"].present?
photo = Photo.find(params["id"])
if params['key'].present?
photo.key = params['key']
photo.remote_image_url = photo.image.direct_fog_url(:with_path => true)
photo.image_name = params['key'].split('/').last
photo.save(validate: false)
puts photo.inspect
end
else
#photo = site.photos.build
#photo.hotel_detail_id = site.hotel_detail.id
#photo.album_id = site.hotel_detail.album.id
#photo.save(validate: false)
photo.key = params['key']
photo.remote_image_url = photo.image.direct_fog_url(:with_path => true)
#photo.image = params['key']
#photo.remote_image_url = params['key']
photo.image_name = params['key'].split('/').last
puts photo.inspect
photo.save(validate: false)
end
if params["id"].present? && params["crop_x"].present?
photo.crop_x = params["crop_x"]
photo.crop_y = params["crop_y"]
photo.crop_w = params["crop_w"]
photo.crop_h = params["crop_h"]
photo.save(validate: false)
end
if params["id"].present?
if params['key'].present?
s3 = AWS::S3.new.buckets[ENV["FOG_DIRECTORY"]]
s3.objects[params['key']].delete
end
else
AmazonFile.new(params['key']).delete
end
puts "Deleted temp file: #{params['key']}" if params['key'].present?
puts "Photo(#{photo.id}) saved successfully. URL: #{params['key']}"
rescue Exception => exc
#puts "Photo not saved. URL: #{params['key']}"
puts "Error: #{exc.message}"
end
end
end
除了 sidekiq,我还在使用 carrierwave_backgrounder
gem。
我正在使用 Kraken 进行图像压缩
照片 uploader
class PhotoUploader < CarrierWave::Uploader::Base
#include ::CarrierWave::Backgrounder::Delay
include CarrierWaveDirect::Uploader
include CarrierWave::MiniMagick
include CarrierWave::MimeTypes
process :set_content_type
process :crop
storage :fog
after :store, :kraken
version :admin do
process :resize_to_fit => [200,200]
end
#Leisure theme
version :leisure_358x243, :if => :leisure_theme? do
process :resize_to_fill => [358,243]
end
version :leisure_900x500, :if => :leisure_theme? do
process :resize_to_fill => [900,500]
end
version :leisure_350x147, :if => :leisure_theme? do
process :resize_to_fill => [350,147]
end
version :leisure_1100x344, :if => :leisure_theme? do
process :resize_to_fill => [1100,344]
end
#Business theme
version :business_360x160, :if => :business_theme? do
process :resize_to_fill => [360,160]
end
version :business_1100x315, :if => :business_theme? do
process :resize_to_fill => [1100,315]
end
version :business_1140x530, :if => :business_theme? do
process :resize_to_fill => [1140,530]
end
version :business_1100x355, :if => :business_theme? do
process :resize_to_fill => [1100,355]
end
#Commthree theme
version :commthree_550x300, :if => :commthree_theme? do
process :resize_to_fill => [550,300]
end
version :commthree_319x183, :if => :commthree_theme? do
process :resize_to_fill => [319,183]
end
version :commthree_1920x700, :if => :commthree_theme? do
process :resize_to_fill => [1920,700]
end
#All theme
version :all_360x188 do
process :resize_to_fill => [360,188]
end
version :all_1100x401 do
process :resize_to_fill => [1100,401]
end
version :all_140x88 do
process :resize_to_fill => [140,88]
end
def kraken(file)
if version_name.to_s == ""
storepath = store_dir + "/" + filename
else
fname = filename.split('.')
#originalfile = "http://s3.amazonaws.com/" + ENV["FOG_DIRECTORY"] + "/" + store_dir + "/" + fname[0] + "_" + version_name.to_s + "." + fname.last
storepath = store_dir + "/" + fname[0] + "_" + version_name.to_s + "." + fname.last
end
originalfile = "http://s3.amazonaws.com/" + ENV["FOG_DIRECTORY"] + "/" + store_dir + "/" + filename
kraken = Kraken::API.new(
:api_key => ENV['KRAKEN_API'],
:api_secret => ENV['KRAKEN_SECRET']
)
params = {}
Rails.logger.info('Kraken About to Process: ' + originalfile);
p "version #{version_name}"
case version_name.to_s
when "admin"
params = {
'lossy' => true,
'resize' => {
'width' => 200,
'height' => 200,
'strategy' => "auto",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "leisure_358x243"
params = {
'lossy' => true,
'resize' => {
'width' => 358,
'height' => 243,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "leisure_900x500"
params = {
'lossy' => true,
'resize' => {
'width' => 900,
'height' => 500,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "leisure_350x147"
params = {
'lossy' => true,
'resize' => {
'width' => 350,
'height' => 147,
'strategy' => "exact",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "leisure_1100x344"
params = {
'lossy' => true,
'resize' => {
'width' => 1100,
'height' => 344,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "business_360x160"
params = {
'lossy' => true,
'resize' => {
'width' => 360,
'height' => 160,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "business_1100x315"
params = {
'lossy' => true,
'resize' => {
'width' => 1100,
'height' => 315,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "business_1140x530"
params = {
'lossy' => true,
'resize' => {
'width' => 1140,
'height' => 530,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "business_1100x355"
params = {
'lossy' => true,
'resize' => {
'width' => 1100,
'height' => 355,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "commthree_550x300"
params = {
'lossy' => true,
'resize' => {
'width' => 550,
'height' => 300,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "commthree_319x183"
params = {
'lossy' => true,
'resize' => {
'width' => 319,
'height' => 183,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "commthree_1920x700"
params = {
'lossy' => true,
'resize' => {
'width' => 1920,
'height' => 700,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "all_360x188"
params = {
'lossy' => true,
'resize' => {
'width' => 360,
'height' => 188,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "all_1100x401"
params = {
'lossy' => true,
'resize' => {
'width' => 1100,
'height' => 401,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
when "all_140x88"
params = {
'lossy' => true,
'resize' => {
'width' => 140,
'height' => 88,
'strategy' => "fit",
},
's3_store' => {
'key' => ENV['AWS_ACCESS_KEY_ID'],
'secret' => ENV["AWS_SECRET_ACCESS_KEY"],
'bucket' => ENV["FOG_DIRECTORY"],
'acl' => 'public_read',
'path' => storepath
},
}
end
#Store the file online
if !version_name.blank?
Rails.logger.info('UPLOADING TO: ' + store_path);
data = kraken.url(originalfile,params)
if data.success
Rails.logger.info('KRAKEN: Success! Optimized image URL: ' + data.kraked_url)
else
puts
Rails.logger.info('KRAKEN: Fail. Error message: ' + data.message)
end
end
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# def cache_dir
# "#{Rails.root}/tmp/uploads"
# end
def store_dir
if model.id.present?
"photos/#{model.id}"
else
"photos"
end
end
#file name is missing extension!!!
def filename
original_filename if original_filename.present?
end
def crop
puts "i am uploader"
if model.crop_x.present?
manipulate! do |img|
puts "i am cropping"
cx = model.crop_x.to_i
cy = model.crop_y.to_i
cw = model.crop_w.to_i
ch = model.crop_h.to_i
img.crop"#{cw}x#{ch}+#{cx}+#{cy}"
#img
end
end
end
def business_theme? (image)
p "model:#{model.id}"
(model.hotel_detail.site.theme.layout == "x1")if model.id.present?
end
def leisure_theme? (image)
p "model:#{model.id}"
(model.hotel_detail.site.theme.layout == "x2")if model.id.present?
end
def commthree_theme? (image)
p "model:#{model.id}"
(model.hotel_detail.site.theme.layout == "x3") if model.id.present?
end
protected
def secure_token(length=16)
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(length/2))
end
end
请建议我如何计算 WEB_CONCURRENCY
的正确值。
最佳答案
看起来您正在使用 minimagick 和 kraken 进行图像处理。如果您完全迁移到 Kraken 并让它们处理您所有的图像处理,您的工作人员的内存应该不会有问题。
删除所有版本,看看是否能提高性能。
version :leisure_358x243, :if => :leisure_theme? do
process :resize_to_fill => [358,243]
end
如果您想坚持在您的 worker 上处理图像,可以使用比 carrierwave-minimagick 更高效的库。看看carrierwave-vips .
关于ruby-on-rails - 在 heroku 上设置 WEB_CONCURRENCY 的公式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27704827/
我对为什么我的 Excel 工作簿中的 if 公式不起作用感到目瞪口呆。 像 =if(F2=0, TRUE, FALSE) 这样简单的事情会引发一般错误“这个公式有问题”。不知道在哪里可以解决这个问题
在链接的电子表格中,我试图总结从一月到单元格 B1 中的日期的列 R 类别的所有实例(对于这个例子,让我们说“CAM 收入”)。 在这种情况下,总和应该是 ( B7:F7 ) 和 ( B9:F9 )
这是一个两部分的问题。我想根据价格的生效日期查找商品的价格。我看过垂直生效日期的例子,但我的有点不同。我在第一列 (A) 中有项目。其余列包含带有价格生效日期的标题。希望我能够附上格式示例。我以这种方
我想从第一个单元格开始自动增加月份。 A1 = 2019-01 以下单元格中的公式应自动填充其余单元格。 A2 = 2019-02 : : A13 = 2020-01 有没有一种简单的方法可以做到这一
在 Excel 中,如果 2021 年是基准年(第 1 年),并且我正在以月份为单位进行财务模型(但仍想知道该月份对应于哪一年),我可以使用什么公式来表示月份 0- 12 是第 1 年,第 13-24
我有以下公式,但它不起作用,因为当我在名称周围添加加利福尼亚时它只是失败了,所以它只是告诉我一切都是英国。我怎样才能解决这个问题? =IF(OR(N10776="*California*",N1077
我有这个公式: =IF(AD491="In progress" OR AD491="Reopened"(ROUND($BW$1-AI491,0),($BW$1-BB491+1)) 它正在检查单元格 A
我想做一个总结表。 我创建了一个名称下拉列表:Bob、Jack、Beth 和一个包含两个选项的下拉列表:已完成或更正待定。 在任务旁边的 Sheet2 上,您将选择名称,然后选择两个选项之一。 在摘要
如果我在 A 列中有以下数据: A1 = 3.5.15 A2 = 2.6 A3 = 8.4.3.16.7 我想要一个公式,它可以在下一列 B 中返回以下内容: B1 = 3.5 B2 = 2 B3 =
我在 Excel 2013 中有一张水果表。 我想通过从当前行到顶部搜索直到第一次出现“::”来填充“类别”列,这是表中类别的关键字。 如果有某种方法可以反转范围,我可以执行类似 "=Match(":
我这里有 2 张 table : 我要填写Code表 1 中的列,引用表 2。值的条件是开始日期必须在 ProductionDate 之间。和 ExpiryDate表 2 的类型,表 1 中的类型必须
我有以下工作表: 网格填充有以下公式(此示例来自单元格 H4),该公式根据左侧表格中的输入填充网格,=IF($A4="","",IF(AND($E4="Daily",H$2>=$D4,H$2=$D4,
我在 A1 中有以下值。当我向下拖动时,它应该以如下所示的方式增加。 B 应该首先增加,保持 C 不变。一旦 B 达到最大值,即 2,则 C 应该增加。 C 的最大值实际上取决于行号,行号除以 2 或
我会尽我所能理解这一点。我很讨厌把事情说清楚。 :) 所以……就这样…… 我有一张电子表格,上面列出了我种植辣椒的种子。这是我的专栏,我会在后面解释更多。 裁剪 |颜色 |一代 |物种 |来源 |斯科
我在 Excel 电子表格中有两个列表。 第一个列表有字符串,例如 1234 blue 6 abc xyz blue/white 1234 abc yellow 123 另一个列表包含第一个列表的子字
我正在尝试创建一个 SumIf 公式,该公式根据一个标准将多个列添加在一起。 =sumif(F$8:F$58,F73,L$8:L$58+I$8:I$58) 这给了我一个错误,并且不会将两列加在一起。
你好我想知道是否有一个公式相当于每个语句。 我知道使用 VBA 可以做到这一点,但鉴于这是一份官方报告,我更愿意让它无宏。 基本上我有一个列(假设是 A),其中包含支付发票的时间 ` |------
任何用于计算频率表中数据平均值(众数、标准差、...)的简单 Excel 公式,如下所示: value frequency 5 3 8 5 4 1
例如:您希望在 Z# 年的每年年初以今天的美元收到 $X。假设 3% 的恒定通货膨胀率和 7% 的复合年返回率。 我知道计算通货膨胀调整后 yield 的公式;对于返回率,您必须使用以下公式: [[(
需要一些帮助来找出一个公式来计算一个值在列中列出的次数。我将尝试解释下面的要求。 下图显示了数据集的示例。 要求是列出每个客户的问题和行动。 如您所见,即使从单元格中聚集的值中,我们也需要找出各个唯一
我是一名优秀的程序员,十分优秀!