Skip to content

Instantly share code, notes, and snippets.

@DavidAntaramian
Last active July 27, 2018 01:42
Show Gist options
  • Save DavidAntaramian/da633423b822b70badfd18c9909c8207 to your computer and use it in GitHub Desktop.
Save DavidAntaramian/da633423b822b70badfd18c9909c8207 to your computer and use it in GitHub Desktop.
defmodule LoadTester do
@table_name :http_results
@url "https://example.com"
def test() do
tab =
:ets.new(table_name, [
:set,
:named_table,
:public,
read_concurrency: true,
write_concurrency: true
])
for i <- 1..100_000, do: Task.async(&make_request/0)
:ets.tab2list(@table_name)
|> Enum.sort(fn {s, _} -> s end)
|> Enum.each(fn {s, c} -> IO.puts("Encountered #{s} #{c} times") end)
end
def make_request() do
case :hackney.request(:get, @url, [], "", with_body: true) do
{:ok, status, _, _} ->
:ets.update_counter(@table_name, status, {2, 1}, {status, 0})
{:error, _} ->
:ets.update_counter(@table_name, :error, {2, 1}, {:error, 0})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment