0
我的應用程序真的非常非常困難,它看起來與數據庫有關。該應用程序處理大量的大量數據,並同時處理數百個用戶。在努力加快數據加載,我加載一些記錄是這樣的:這種模型方法是否鎖定我的PostgreSQL數據庫?
def load(filename)
rc = Publication.connection.raw_connection
rc.exec("COPY invoice_line_items FROM STDIN WITH CSV HEADER")
# open up your CSV file looping through line by line and getting the line into a format suitable for pg's COPY...
error = false
begin
CSV.foreach(filename) do |line|
until rc.put_copy_data(line.to_csv)
ErrorPrinter.print " waiting for connection to be writable..."
sleep 0.1
end
end
rescue Errno => err
User.inform_admin(false, User.me, "Line Item import failed with #{err.class.name} the following error: #{err.message}", err.backtrace)
error = true
else
rc.put_copy_end
while res = rc.get_result
if (res.result_status != 1)
User.inform_admin(false, User.me, "Line Item import result of COPY was: %s" % [ res.res_status(res.result_status) ], "")
error = true
end
end
end
end
我也Sidekiq約90線程中運行。這種加載方法是否在該表上設置了獨佔鎖?這些工作是否可能互相碰撞?如果他們是,我最好只是做插入?
「真的很難碰到」真令人回味,但沒有提供信息。究竟發生了什麼? – jjanes
應用程序服務器完全停止響應。數據庫中有大量看起來不會移動的進程。 – AKWF