-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.iex.exs
53 lines (45 loc) · 1.3 KB
/
.iex.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
defmodule PLC do
alias Scrub.Session
alias Scrub.CIP.ConnectionManager
def start do
{:ok, session} = Session.start_link("20.0.0.70")
Process.unlink(session)
data = ConnectionManager.encode_service(:large_forward_open)
{:ok, resp} = Session.send_rr_data(session, data)
{:ok, %{orig_network_id: conn}} = ConnectionManager.decode(resp)
{session, conn}
end
def stop do
Session.close(__MODULE__)
end
def run do
{session, conn} = start()
request_tag(session, conn, "REG_PWRUP_MEM")
end
def request_tag(session, conn, path) do
data = ConnectionManager.encode_service(:unconnected_send, request_path: path)
{:ok, resp} = Session.send_unit_data(session, conn, data)
ConnectionManager.decode(resp)
end
def test_speed do
{session, conn} = start()
:timer.tc(fn () ->
Enum.each(1..10_000, fn(_) ->
request_tag(session, conn, "REG_PWRUP_MEM")
end)
end)
end
def multi_speed(tags, sched) do\
shard = (tags / sched) |> floor()
Enum.reduce(1..sched, [], fn(_, acc) -> [start() | acc] end)
|> Enum.each(fn({session, conn}) ->
spawn(fn ->
:timer.tc(fn () ->
Enum.each(1..shard, fn(_) ->
request_tag(session, conn, "REG_PWRUP_MEM")
end)
end)
end)
end)
end
end