erlang 调用www.example.com时什么会导致SystemLimitErrortimer.tc?

e4eetjau  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(204)

我正在用Elixir编写一个简单的模块,将数据加载到用Erlang编写的gen_server中。我需要测量加载操作的时间,这是我遇到的问题。当我timer.tc在第46行(带有crateStations的行)调用www.example.com()时,我得到SystemLimitError,我不知道什么可以导致这样的行为,并将感谢任何提示。贝娄是代码的elxir模块使用,我以前使用过Erlang gen_server,没有发生过这样的错误。

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
rt4zxlrg

rt4zxlrg1#

调用:pollution_gen_server.addStation(nameStation(cords),...)是否会从名称创建一个原子?在这种情况下,您可能会溢出原子表,该表默认有1048576个唯一原子的空间(即刚刚超过一百万个)。如果您无法重写代码,您可以尝试在启动系统时使用+t标志提高级别。

相关问题