total_requests = 10
concurrency = 2
#url = "https://httpbin.org/anything"
method = :get
#payload = '{"some": "data"}'
:inets.start()
# :ssl.start()
average_time =
1..total_requests
|> Task.async_stream(
fn _ ->
start_time = System.monotonic_time()
id = :rand.uniform(10_000) |> Integer.to_charlist()
headers = [{'TransactionID', id}, {'SenderID', 'CON'}, {'Authorization', 'Basic token'}]
url = 'endpoint'
result = :httpc.request(method, {url, headers, 'application/json'}, [], [headers_as_is: true])
IO.puts("#{inspect result}")
System.monotonic_time() - start_time
end,
max_concurrency: concurrency
)
|> Enum.reduce(0, fn {:ok, req_time}, acc ->
acc + req_time
end)
|> System.convert_time_unit(:native, :millisecond)
|> Kernel./(total_requests)
The above elixir script returns the below error
** (FunctionClauseError) no function clause matching in :httpc.request/5
(inets 7.4.1) httpc.erl:149: :httpc.request(:get, {‘endpoint’, [{‘TransactionID’, ‘3742’}, {‘SenderID’, ‘CON’}, {‘Authorization’, ‘Basic Auth’}], [‘application/json’], ‘hi’}, [], [], :default)
I’m not quite sure how :default
is being added to the function triggering the above error.