我有一个简单的工作,它加载一个大的json文件并在数据库中创建/更新记录。该工作通过 sidekiq 执行。
以下是该作业的简化版本:
def call
clients_data = HTTParty.get(@url).parsed_response
create_or_update_clients(clients_data)
end
private
def create_or_update_clients(clients_data)
clients_data.each do |client_item|
begin
process_remote_client(client_item)
rescue => e
Appsignal.add_exception(e)
end
end
end
def process_remote_client(client_item)
client = Client.find_or_initialize_by(reference: client_item['ID']) do |new_client|
new_client.company = @company
end
client.save!
end
即使数据是在循环中处理的,内存也会随着时间的推移而增加。然后重新启动sidekiq,因为内存消耗超过了阈值。
有没有解释为什么内存没有被重用?