Tcp buffer reuse for lower memory use

2023-04-14 Thread andyroyes
Nothing actually work for me seems like can't do it out of the box and need's more then i thought but enjoyed so far. Maybe i will try again when i have more time. Thank you for your time.

Tcp buffer reuse for lower memory use

2023-04-13 Thread elcritch
Your first attempt with cstring didn't allocate memory for the cstring, hence the data corruption. I'm not sure why the memory usage would increase over time. It might be async related. You could try Chronos async as they've done a lot of work on memory usage with their async impl. Otherwise you

Tcp buffer reuse for lower memory use

2023-04-13 Thread Calonger
Perhaps ... ? proc remoteHasData() {.async.} = var buf : array[1024 , char] while not remote.isClosed and not remote.isClosed: let n = await remote.recvInto(unsafeAddr buf[0],1024) await client.send(unsafeAddr buf[0], n) client.close()

Tcp buffer reuse for lower memory use

2023-04-13 Thread andyroyes
This works and reduced to half 3MB but still not near my goal and also slowly memory increases when running for long. proc remoteHasData() {.async.} = var buf = newString(1024) while not remote.isClosed and not remote.isClosed: let n = await remote.recvInto(

Tcp buffer reuse for lower memory use

2023-04-13 Thread andyroyes
@elcritch Tried doing this writes malformed data to remote connection can you provide me little snipet kindly. thank you proc clientHasData() {.async.} = var buf: cstring while not client.isClosed and not remote.isClosed: let n = await client.recvInto(addr(

Tcp buffer reuse for lower memory use

2023-04-12 Thread elcritch
The stdlib does provide methods to read data into existing buffer's. I've used it a fair bit on embedded devices, though mostly non-async. The easiest way to structure it in Nim to prevent copying I've found is to pass the buffer as an openArray parameter. Unfortunately the net functions don't

Tcp buffer reuse for lower memory use

2023-04-12 Thread termer
Oh yeah, in a thread about HTTP servers recently, someone mentioned how asyncnet buffers reads. That same person had a patch back in 2017 to avoid doing that, here's the patch if it's useful to you

Tcp buffer reuse for lower memory use

2023-04-12 Thread termer
My bad, I misunderstood. I will say that my original comment about C still holds true; you can interface directly with the kernel. My assumption here is that you're talking about asyncnet though, right? If you want, you can use the `selectors` library in the stdlib to do the calls yourself and h

Tcp buffer reuse for lower memory use

2023-04-12 Thread andyroyes
@termer this feature is only available on the Linux kernel and I was not talking about this. I am sorry for not providing detail I want to allocate once and reuse that memory to read and write multiple times. In the initial question, I talked about golang io.CoppyBufer() which will allocate once

Tcp buffer reuse for lower memory use

2023-04-12 Thread termer
If it's possible in C then it's possible in Nim. The question is whether you want to go down that low and do it yourself. If you want to interact with kernel buffers, you could try implementing something with io_uring if you're on Linux. Someone's working on a [Nim port of liburing](https://git

Tcp buffer reuse for lower memory use

2023-04-12 Thread andyroyes
@mildred nim is fast and small and because of this I wanted to use it in small spaces networking environment where every byte matters but seems like nim doesn't have enough maturity when it comes to networking, I don't understand why reading from tcp returns strings in nim. So is it not possible

Tcp buffer reuse for lower memory use

2023-04-12 Thread andyroyes
@sls1005 your example does not work got this error : type mismatch: got

Tcp buffer reuse for lower memory use

2023-04-11 Thread sls1005
You can do something like: proc clientHasData() {.async.} = var data = newString(1024) while not client.isClosed and not remote.isClosed: let n = await client.recv(data, 1024) await remote.send(pointer(data.cstring), len(data)) client.close() re

Tcp buffer reuse for lower memory use

2023-04-11 Thread andyroyes
This is the **Nimlang** code I am using which is a very simple **TCP** forwarder but it consumes about **6MB** of memory to accomplish this in **Golang** I achieve this same task under **1.5MB** of memory and has a very efficient and reliable function **io.CopyBuffer()** which can be used to co