0
votes

I am writing a simple module in Elixir that loads data into a gen_server written in Erlang. I need to measure time of loading operations, and this is the thing I have problem with. When I call :timer.tc() on line 46 (the one with crateStations) I get SystemLimitError, I have no idea what can cause such behaviour and would be grateful for any tips. Bellow is the code for elxir module used, I have worked with the Erlang gen_server previously and no such errors occurred.

defmodule Data do

  defp nameStation({:cords,lat,lang}) do
    "station_#{lang}_#{lat}}}"
  end

  defp identifyStations(data) do
    data |> Enum.map((&(&1.location))) |> Enum.uniq |> Enum.map((fn({lat,lang})->{:cords,lat,lang}end))
  end

  defp createStations(data)do
    identifyStations(data) |>
    Enum.each((fn (cords)->:pollution_gen_server.addStation(nameStation(cords),cords) end))
  end

  defp createMesurements(data) do
    data |> Enum.each((fn(value)->
                       :pollution_gen_server.addValue(value.location,value.datetime,"PM10",value.pollutionLevel ) end))
  end

  defp importLinesFromCSV(path) do
    File.read!(path) |> (&(String.split(&1, "\r\n"))).()
  end

  defp parse(line) do
    [date_l,time_l,lang_l,lat_l,polltion_l] = String.split(line,",")
    lat = lat_l |> Float.parse() |> elem(0)
    lang = lang_l |> Float.parse() |> elem(0)
    pollution = polltion_l |> Integer.parse() |> elem(0)
    {hours,mins} = time_l |> String.split(":")  |> Enum.map(&(Integer.parse/1)) |>Enum.map(&(elem(&1,0))) |>
           :erlang.list_to_tuple()
    date = date_l |>  String.split(":") |> Enum.map(&(Integer.parse/1)) |> Enum.reverse() |>Enum.map(&(elem(&1,0))) |>
           :erlang.list_to_tuple()
    %{
      :datetime => {date,{hours,mins,0}},
      :location => {lat,lang},
      :pollutionLevel => pollution
    }
  end


  def run(path) do
    :pollution_sup.start_link()
    lines = importLinesFromCSV(path) |> Enum.map(&parse/1)

    time_stations = :timer.tc(&createStations/1,lines) |> elem(0) |> Kernel./(1_000_000)
    time_measurements = :timer.tc(&createMesurements/1,lines) |> elem(0) |> Kernel./(1_000_000)

    time_mean = :timer.tc(&:pollution_gen_server.getStationMean/2,["PM10",{:cords, 49.986, 20.06}]) |> elem(0) |> Kernel./(1_000_000)
    mean = :pollution_gen_server.getStationMean("PM10",{:cords, 49.986, 20.06})

    time_daily = :timer.tc(&:pollution_gen_server.getDailyMean/2,["PM10",{2017, 5, 3}]) |> elem(0) |> Kernel./(1_000_000)
     daily = :pollution_gen_server.getDailyMean("PM10",{2017, 5, 3})

     IO.puts "Time of loading stations: #{time_stations}"
     IO.puts "Time of loading mesurements: #{time_measurements}"

     IO.puts "Time of getting mean: #{time_mean} result: #{mean}"
     IO.puts "Time of getting daily: #{time_daily} result: #{daily}"
  end

end
1
Please provide an MCVE and post the stacktrace of the error. - Aleksei Matiushkin
A system limit error suggests that one of these limits has been exceeded. Wild guess: are you starting more than 262,144 processes? - legoscia

1 Answers

0
votes

Does the call :pollution_gen_server.addStation(nameStation(cords),...) create an atom from the name? In that case, you could be overflowing the atom table, which by default has room for 1048576 unique atoms (i.e., just over a million). If you can't rewrite the code, you could try raising the level with the +t flag when starting the system.