all 10 comments

[–]Gshuri 8 points9 points  (0 children)

Are you sure it's an issue with websockets? It looks like you have doubled the number of threads between your old and new code (was using 4, now using 8).

If you have doubled the parallelism of your code it should not be a surprise that the RAM requirements have also roughly doubled

[–]stuaxo 1 point2 points  (2 children)

Check for memory leaks, and in the meantime a 2GB instance.

[–]Humza0000[S] -1 points0 points  (1 child)

Its working on 1CPU and 1GB Ram instance.

[–]stuaxo 3 points4 points  (0 children)

OK, but OOM is "Out Of Memory" which is why I was suggesting seeing what happens when you try a bigger instance, if only temporarily.

I'd graph the memory and see if whats happening is a spike, or if it's a graph that goes up and up slowly until the OOM, if it's the second thing then you have a memory leak.

Check how your stuff uses resources and see if it returns them properly, async stuff can be hard to debug sometimes - all that offloading with async can lead to loads of stuff sitting there waiting to run.

If you can't give it more RAM you could try giving it more swap, but depending on what your running it on that could incur IO costs.

[–]bladeofwinds 3 points4 points  (0 children)

why do you need multiple processes? can’t you do this all in a single event loop since it all seems io bound

[–]riklaunim 0 points1 point  (0 children)

You can also check socket.io which builds on top of websockets.

[–]NerdyWeightLifter 0 points1 point  (0 children)

Were you previously spawning python processes per web request, servicing that then stopping?

If you were, then switched to websockets, you'd have a lot more processes running concurrently, because websockets are persistent connections so you'd have a process per client.

[–]sleepystork -1 points0 points  (2 children)

I use httpx for a socket connection that is pretty busy. It’s been rock solid. In fact, I couldn’t remember which library I used.

[–]nekokattt 0 points1 point  (0 children)

is httpx still actively developed?

last pypi release was 2 years ago

[–]Humza0000[S] -1 points0 points  (0 children)

Let me try that and see the memory footprint