質問編集履歴
4
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -87,4 +87,23 @@
|
|
87
87
|
memory using 305.225944 MB
|
88
88
|
memory using 308.89255099999997 MB
|
89
89
|
memory using 317.53945500000003 MB →puma-worker-killer発動
|
90
|
+
```
|
91
|
+
|
92
|
+
# 追記3
|
93
|
+
find_in_batches(:batch_size => 100)の時のメモリ状況
|
94
|
+
ダウンロードできました。が、メモリ増加は改善しませんでした。
|
95
|
+
```ここに言語を入力
|
96
|
+
・
|
97
|
+
・
|
98
|
+
・
|
99
|
+
memory using 618.732024 MB
|
100
|
+
memory using 619.4192240000001 MB
|
101
|
+
memory using 620.1064240000001 MB
|
102
|
+
memory using 620.79362 MB
|
103
|
+
memory using 621.48081 MB
|
104
|
+
memory using 622.1680080000001 MB
|
105
|
+
memory using 622.842653 MB
|
106
|
+
memory using 623.016078 MB
|
107
|
+
memory using 623.900232 MB
|
108
|
+
memory using 621.7092120000001 MB
|
90
109
|
```
|
3
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
values = record.csv_column_values
|
31
31
|
y << encode_sjis(values.map{|k, v| v.call(record)}.to_csv)
|
32
32
|
end
|
33
|
+
GC.start
|
33
34
|
Rails.logger.info "memory using #{ObjectSpace.memsize_of_all * 0.001 * 0.001} MB" #追記
|
34
35
|
end
|
35
36
|
end
|
@@ -64,4 +65,26 @@
|
|
64
65
|
memory using 333.15229800000003 MB
|
65
66
|
memory using 352.51917 MB
|
66
67
|
memory using 368.840598 MB
|
68
|
+
```
|
69
|
+
|
70
|
+
# 追記2
|
71
|
+
■Rails.logger.infoの前にGC.startを追加した後のメモリ使用量
|
72
|
+
先程に比べるの一定してメモリが増えるようになりました。
|
73
|
+
```ここに言語を入力
|
74
|
+
memory using 173.27937400000002 MB
|
75
|
+
memory using 211.016275 MB
|
76
|
+
memory using 218.16826200000003 MB
|
77
|
+
memory using 224.72966 MB
|
78
|
+
memory using 234.490212 MB
|
79
|
+
memory using 241.19169300000001 MB
|
80
|
+
memory using 248.46728700000003 MB
|
81
|
+
memory using 256.185135 MB
|
82
|
+
memory using 265.241077 MB
|
83
|
+
memory using 272.950707 MB
|
84
|
+
memory using 279.282393 MB
|
85
|
+
memory using 287.88837800000005 MB
|
86
|
+
memory using 295.887373 MB
|
87
|
+
memory using 305.225944 MB
|
88
|
+
memory using 308.89255099999997 MB
|
89
|
+
memory using 317.53945500000003 MB →puma-worker-killer発動
|
67
90
|
```
|
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,6 +30,7 @@
|
|
30
30
|
values = record.csv_column_values
|
31
31
|
y << encode_sjis(values.map{|k, v| v.call(record)}.to_csv)
|
32
32
|
end
|
33
|
+
Rails.logger.info "memory using #{ObjectSpace.memsize_of_all * 0.001 * 0.001} MB" #追記
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
@@ -37,4 +38,30 @@
|
|
37
38
|
```
|
38
39
|
|
39
40
|
### 試したこと
|
40
|
-
render_csvの中で`find_each`や`find_in_batches`を500件や100件ずつで試してみましたが、状況は変わらず。
|
41
|
+
render_csvの中で`find_each`や`find_in_batches`を500件や100件ずつで試してみましたが、状況は変わらず。
|
42
|
+
|
43
|
+
# 追記
|
44
|
+
■コードに追加した内容
|
45
|
+
Rails.logger.info "memory using #{ObjectSpace.memsize_of_all * 0.001 * 0.001} MB"
|
46
|
+
|
47
|
+
■以下、tail -f development.log | grep --line-buffered "memory using"の結果です。
|
48
|
+
memory using 368.840598 MBでpuma-worker-killerが発動しています。
|
49
|
+
```
|
50
|
+
memory using 185.512727 MB
|
51
|
+
memory using 236.11603 MB
|
52
|
+
memory using 218.543507 MB
|
53
|
+
memory using 249.18884 MB
|
54
|
+
memory using 258.381909 MB
|
55
|
+
memory using 238.562832 MB
|
56
|
+
memory using 325.655192 MB
|
57
|
+
memory using 320.25811200000004 MB
|
58
|
+
memory using 286.946893 MB
|
59
|
+
memory using 313.74037 MB
|
60
|
+
memory using 276.651044 MB
|
61
|
+
memory using 296.949558 MB
|
62
|
+
memory using 311.553982 MB
|
63
|
+
memory using 302.603379 MB
|
64
|
+
memory using 333.15229800000003 MB
|
65
|
+
memory using 352.51917 MB
|
66
|
+
memory using 368.840598 MB
|
67
|
+
```
|
1
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,8 +10,27 @@
|
|
10
10
|
```ruby
|
11
11
|
class ExportsController < ApplicationController
|
12
12
|
def index
|
13
|
+
items = Item.all
|
13
|
-
|
14
|
+
render_csv(items)
|
15
|
+
end
|
16
|
+
|
14
|
-
|
17
|
+
def render_csv(records)
|
18
|
+
filename = "Item_#{Time.current.to_i}.csv"
|
19
|
+
self.response.headers['Content-Type'] ||= 'text/csv; charset=Shift_JIS'
|
20
|
+
self.response.headers['Content-Disposition'] = "attachment;filename=#{filename}"
|
21
|
+
self.response.headers['Content-Transfer-Encoding'] = 'binary'
|
22
|
+
self.response.headers['Last-Modified'] = Time.current.ctime.to_s
|
23
|
+
|
24
|
+
self.response_body = Enumerator.new do |y|
|
25
|
+
names = Item.csv_column_names
|
26
|
+
y << encode_sjis(names.values.to_csv)
|
27
|
+
|
28
|
+
records.find_in_batches do |group|
|
29
|
+
group.each do |record|
|
30
|
+
values = record.csv_column_values
|
31
|
+
y << encode_sjis(values.map{|k, v| v.call(record)}.to_csv)
|
32
|
+
end
|
33
|
+
end
|
15
34
|
end
|
16
35
|
end
|
17
36
|
end
|