I’m wondering if anyone has any suggestions or pointers for troubleshooting poor performance on an EC2 instance.
Using top
, I noticed that CPU usage was way up (e.g. 200%) – that was easy to fix: I had put a huge pool size for the PostGres instance. Once I brought that down and restarted the app, top
showed everything as normal.
I started processing files – there are maybe 100 long txt files, each with maybe a quarter million lines. The script is mostly formatting each line and streaming to an output file using a pattern like this:
input_files = [
# list of input files
]
Task.Supervisor.async_stream_nolink(
TmpTaskSupervisor,
input_files,
fn input_file ->
{:ok, output_file} = File.open(input_file <> ".parsed", [:append, {:delayed_write, 500, 200}])
lines = File.stream!(input_file)
lines
|> Stream.with_index()
|> Stream.each(fn {line, _index} ->
{:ok, parsed} = parse(line)
IO.binwrite(output_file, Jason.encode!(parsed) <> "\n")
end)
|> Stream.run()
end,
timeout: 100_000,
max_concurrency: 25
)
|> Enum.to_list()
I’ve played around with the max_concurrency
… the performance seems to stay more or less the same.
On my local laptop, this completes in a couple hours. But on EC2, this takes days and days. The input and output files are on an attached EFS volume – I’m not sure if that makes any difference. I tried writing to the local volume where the app is running, but there was no change in the performance.
What is significant is that on my local laptop, top
shows that BEAM is gobbling up CPU – it spikes up to 200%. But on the EC2 instance, top
shows very little activity for CPU, e.g. maybe 30% or 40% tops.
Can anyone recommend some other ways to troubleshoot a performance issue like this?
Thanks in advance!