I am looking to prepare a tcp listener which is capable of listening several thousands of concurrent connections (maybe tens of thousands). Yes not millions etc. Ok, maybe not like zeromq(zeromq.org) but something like quarter * quarter or less of it maybe?? I tried Python asyncio and tornado , but in my case i am using economical 2 Core, 1-2 Gig virtual servers which is becoming unstable even after several hundered concurrent connections something like 450s... I didn't understand much maybe because of limits of my provider's KVM virtualisation, something is going wrong after several hundereds, also i tuned ulimit etc... Socket is crashing and i couldn't get any reply from console. So, i am in between vertx and nim. But nim is kind of well documented and much more actively maintained than others? . - I know there are also Crystal, Julia etc. Nobody knows but Perl 6. I was looking for Golang's, C# Kestrel's capabilities. Even golang is crashing down after 450s of connections. :( NodeJS no hope. So should i put them after Nginx or something like that?
There were also another problem for database inserting. I was planning to insert the data received from client to postgres. In Python, while using Async Postgres also it couldn't satisfy me.
I am looking for any kind of advices to make durable tcp listener which can get a json from client and insert it to SQL without exploding itself.
Example below is looking good for me. This is why i said nim is well documented just like Python.
import asyncnet, asyncdispatch
var clients {.threadvar.}: seq[AsyncSocket]
proc processClient(client: AsyncSocket) {.async.} =
while true:
let line = await client.recvLine()
if line.len == 0: break
for c in clients:
await c.send(line & "\c\L")
proc serve() {.async.} =
clients = @[]
var server = newAsyncSocket()
server.setSockOpt(OptReuseAddr, true)
server.bindAddr(Port(12345))
server.listen()
while true:
let client = await server.accept()
clients.add client
asyncCheck processClient(client)
asyncCheck serve()
runForever()