Hi,
I am using the HTTP.jl module to create multiple websocket connections and process data from them with @async. In the following program I see only 8 tasks ever succeeding. All the connections are going to be up longterm and they serve data at varying rates.
Using Julia 1.6.0
OSs tested: Windows 10 Home, WSL2, Ubuntu 20.04
asynctest.jl
using JSON3, HTTP
const REST_URL = "https://api.pro.coinbase.com"
const WS_URL = "wss://ws-feed.pro.coinbase.com"
const PRODUCTS_URL = REST_URL * "/products"
function get_products()
products = HTTP.request("GET", PRODUCTS_URL)
prod_list = JSON3.read(products.body)
return prod_list
end
prod_list = get_products()
println("Num Symbols:", size(prod_list))
global num_messages = 0
global num_subscribed = 0
@sync for prod in prod_list
sleep(1)
symbol = prod.id
println(symbol)
println("num_subscribed:", num_subscribed)
t = @async HTTP.WebSockets.open(WS_URL) do ws
global num_messages
global num_subscribed
subscribe = """{"type":"subscribe", "product_ids":["$symbol"], "channels": ["full"]}"""
write(ws, subscribe)
num_subscribed += 1
println("async num_subscribed:", num_subscribed)
while !eof(ws)
num_messages += 1
msg = readavailable(ws)
if (num_messages % 10000) == 0
println("num_messages:", num_messages)
end
end
end
end
The following output is seen
output
C:\testprogs\julia>julia asynctest.jl
Num Symbols:(162,)
EOS-BTC
num_subscribed:0
MATIC-USD
num_subscribed:0
async num_subscribed:1
async num_subscribed:2
SUSHI-USD
num_subscribed:2
async num_subscribed:3
LINK-USD
num_subscribed:3
async num_subscribed:4
XTZ-BTC
num_subscribed:4
async num_subscribed:5
BCH-GBP
num_subscribed:5
async num_subscribed:6
LRC-BTC
num_subscribed:6
async num_subscribed:7
REN-BTC
num_subscribed:7
async num_subscribed:8
BNT-BTC
num_subscribed:8
YFI-BTC
num_subscribed:8
COMP-BTC
num_subscribed:8
NMR-USD
num_subscribed:8
The async_num_subscribed never goes above 8. I am fairly new to julia and maybe i am making some elementary errors. Looking for some guidance.
Bharat