質問編集履歴
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -177,3 +177,41 @@
|
|
177
177
|
memory using 317.53945500000003 MB →puma-worker-killer発動
|
178
178
|
|
179
179
|
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
# 追記3
|
184
|
+
|
185
|
+
find_in_batches(:batch_size => 100)の時のメモリ状況
|
186
|
+
|
187
|
+
ダウンロードできました。が、メモリ増加は改善しませんでした。
|
188
|
+
|
189
|
+
```ここに言語を入力
|
190
|
+
|
191
|
+
・
|
192
|
+
|
193
|
+
・
|
194
|
+
|
195
|
+
・
|
196
|
+
|
197
|
+
memory using 618.732024 MB
|
198
|
+
|
199
|
+
memory using 619.4192240000001 MB
|
200
|
+
|
201
|
+
memory using 620.1064240000001 MB
|
202
|
+
|
203
|
+
memory using 620.79362 MB
|
204
|
+
|
205
|
+
memory using 621.48081 MB
|
206
|
+
|
207
|
+
memory using 622.1680080000001 MB
|
208
|
+
|
209
|
+
memory using 622.842653 MB
|
210
|
+
|
211
|
+
memory using 623.016078 MB
|
212
|
+
|
213
|
+
memory using 623.900232 MB
|
214
|
+
|
215
|
+
memory using 621.7092120000001 MB
|
216
|
+
|
217
|
+
```
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -61,6 +61,8 @@
|
|
61
61
|
y << encode_sjis(values.map{|k, v| v.call(record)}.to_csv)
|
62
62
|
|
63
63
|
end
|
64
|
+
|
65
|
+
GC.start
|
64
66
|
|
65
67
|
Rails.logger.info "memory using #{ObjectSpace.memsize_of_all * 0.001 * 0.001} MB" #追記
|
66
68
|
|
@@ -131,3 +133,47 @@
|
|
131
133
|
memory using 368.840598 MB
|
132
134
|
|
133
135
|
```
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
# 追記2
|
140
|
+
|
141
|
+
■Rails.logger.infoの前にGC.startを追加した後のメモリ使用量
|
142
|
+
|
143
|
+
先程に比べるの一定してメモリが増えるようになりました。
|
144
|
+
|
145
|
+
```ここに言語を入力
|
146
|
+
|
147
|
+
memory using 173.27937400000002 MB
|
148
|
+
|
149
|
+
memory using 211.016275 MB
|
150
|
+
|
151
|
+
memory using 218.16826200000003 MB
|
152
|
+
|
153
|
+
memory using 224.72966 MB
|
154
|
+
|
155
|
+
memory using 234.490212 MB
|
156
|
+
|
157
|
+
memory using 241.19169300000001 MB
|
158
|
+
|
159
|
+
memory using 248.46728700000003 MB
|
160
|
+
|
161
|
+
memory using 256.185135 MB
|
162
|
+
|
163
|
+
memory using 265.241077 MB
|
164
|
+
|
165
|
+
memory using 272.950707 MB
|
166
|
+
|
167
|
+
memory using 279.282393 MB
|
168
|
+
|
169
|
+
memory using 287.88837800000005 MB
|
170
|
+
|
171
|
+
memory using 295.887373 MB
|
172
|
+
|
173
|
+
memory using 305.225944 MB
|
174
|
+
|
175
|
+
memory using 308.89255099999997 MB
|
176
|
+
|
177
|
+
memory using 317.53945500000003 MB →puma-worker-killer発動
|
178
|
+
|
179
|
+
```
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,6 +62,8 @@
|
|
62
62
|
|
63
63
|
end
|
64
64
|
|
65
|
+
Rails.logger.info "memory using #{ObjectSpace.memsize_of_all * 0.001 * 0.001} MB" #追記
|
66
|
+
|
65
67
|
end
|
66
68
|
|
67
69
|
end
|
@@ -77,3 +79,55 @@
|
|
77
79
|
### 試したこと
|
78
80
|
|
79
81
|
render_csvの中で`find_each`や`find_in_batches`を500件や100件ずつで試してみましたが、状況は変わらず。
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
# 追記
|
86
|
+
|
87
|
+
■コードに追加した内容
|
88
|
+
|
89
|
+
Rails.logger.info "memory using #{ObjectSpace.memsize_of_all * 0.001 * 0.001} MB"
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
■以下、tail -f development.log | grep --line-buffered "memory using"の結果です。
|
94
|
+
|
95
|
+
memory using 368.840598 MBでpuma-worker-killerが発動しています。
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
memory using 185.512727 MB
|
100
|
+
|
101
|
+
memory using 236.11603 MB
|
102
|
+
|
103
|
+
memory using 218.543507 MB
|
104
|
+
|
105
|
+
memory using 249.18884 MB
|
106
|
+
|
107
|
+
memory using 258.381909 MB
|
108
|
+
|
109
|
+
memory using 238.562832 MB
|
110
|
+
|
111
|
+
memory using 325.655192 MB
|
112
|
+
|
113
|
+
memory using 320.25811200000004 MB
|
114
|
+
|
115
|
+
memory using 286.946893 MB
|
116
|
+
|
117
|
+
memory using 313.74037 MB
|
118
|
+
|
119
|
+
memory using 276.651044 MB
|
120
|
+
|
121
|
+
memory using 296.949558 MB
|
122
|
+
|
123
|
+
memory using 311.553982 MB
|
124
|
+
|
125
|
+
memory using 302.603379 MB
|
126
|
+
|
127
|
+
memory using 333.15229800000003 MB
|
128
|
+
|
129
|
+
memory using 352.51917 MB
|
130
|
+
|
131
|
+
memory using 368.840598 MB
|
132
|
+
|
133
|
+
```
|
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,9 +22,47 @@
|
|
22
22
|
|
23
23
|
def index
|
24
24
|
|
25
|
-
i
|
25
|
+
items = Item.all
|
26
26
|
|
27
|
+
render_csv(items)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
27
|
-
|
33
|
+
def render_csv(records)
|
34
|
+
|
35
|
+
filename = "Item_#{Time.current.to_i}.csv"
|
36
|
+
|
37
|
+
self.response.headers['Content-Type'] ||= 'text/csv; charset=Shift_JIS'
|
38
|
+
|
39
|
+
self.response.headers['Content-Disposition'] = "attachment;filename=#{filename}"
|
40
|
+
|
41
|
+
self.response.headers['Content-Transfer-Encoding'] = 'binary'
|
42
|
+
|
43
|
+
self.response.headers['Last-Modified'] = Time.current.ctime.to_s
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
self.response_body = Enumerator.new do |y|
|
48
|
+
|
49
|
+
names = Item.csv_column_names
|
50
|
+
|
51
|
+
y << encode_sjis(names.values.to_csv)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
records.find_in_batches do |group|
|
56
|
+
|
57
|
+
group.each do |record|
|
58
|
+
|
59
|
+
values = record.csv_column_values
|
60
|
+
|
61
|
+
y << encode_sjis(values.map{|k, v| v.call(record)}.to_csv)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
28
66
|
|
29
67
|
end
|
30
68
|
|