3DS-RPC icon indicating copy to clipboard operation
3DS-RPC copied to clipboard

Optimizing the server into an async server model

Open MayaChen350 opened this issue 4 months ago • 7 comments

So I noticed 3DS-RPC relies a LOT on synchronous libraries, so I took the time to implement some minimal changes for now, like replacing those requests calls to one of a Httpx client.

I wasn't able to setup the project on my environment (Fedora workstation, x86_64) so it might need some testings before to make sure things work fine, but it should definitely make a difference, hopefully even make a lot of problems the project currently has disappear. (Like on the endless issues: #67 #42 etc )

You're welcome!

Please contact me on Discord if you need any more help! I'll be very glad to optimize this project a lot further! Also maybe I'd need some help setting up the project or at least next time as it was way too messy when I tried ^^"

Remember this needs testing!! Wouldn't like for the users to encounter weird race conditions bugs too so it'd be preferable to make sure things work well before

MayaChen350 avatar Aug 20 '25 03:08 MayaChen350

I'm implementing Lazy Evaluation for now, but I'll try to come with something better for the users like a callback system eventually

MayaChen350 avatar Aug 21 '25 17:08 MayaChen350

I added asyncio tasks to run things in "parallel" (still single-threaded)

Basically that way, while one coroutine (basically a task for the program specified to do a single thing at that moment while letting other things proceeed then resume later to finish) for an user is waiting for something to complete, another can take the job, etc

MayaChen350 avatar Aug 21 '25 18:08 MayaChen350

@spotlightishere whenever you have time it'll be really nice if you check this all up. I'm sure this PR could speed up the project a lot so this project could finally get a greater reputation and popularity.

MayaChen350 avatar Aug 21 '25 19:08 MayaChen350

Considering this about pretendo, I'll make sure not to accidentally send too much requests especially if I wrote some in parallel ^^'

For what is for 3ds-rpc server and all though, I'll make sure things dont get too heavy on my current laptop (8gb ram and 8 1ghz cores) to be sure it doesn't cause issues

I was considering creating background threads though but that's probably not something I'll do right now

MayaChen350 avatar Aug 25 '25 16:08 MayaChen350

Considering this about pretendo, I'll make sure not to accidentally send too much requests especially if I wrote some in parallel ^^'

For what is for 3ds-rpc server and all though, I'll make sure things dont get too heavy on my current laptop (8gb ram and 8 1ghz cores) to be sure it doesn't cause issues

I was considering creating background threads though but that's probably not something I'll do right now

You probably want to implement some kind of throttling still for pretendo, since their servers are easy for us to overwhelm and why pretendo is "intentionally" slow

HotaruBlaze avatar Aug 25 '25 16:08 HotaruBlaze

I don't believe any additional throttling changes would be necessary as we still individually add friends, etc outside of this code: https://github.com/3DS-RPC/3DS-RPC/blob/e8188ea383cc09e0726d8d2290a1ea654fa6e420/backend.py#L120-L143

The overwhelming occurs when using sync_friends as their server handles every addition individually, causing strain. We would need to coordinate with them to resolve this throttle.

spotlightishere avatar Aug 25 '25 16:08 spotlightishere

I don't believe any additional throttling changes would be necessary as we still individually add friends, etc outside of this code:

https://github.com/3DS-RPC/3DS-RPC/blob/e8188ea383cc09e0726d8d2290a1ea654fa6e420/backend.py#L120-L143

True, I'm just worried about async deciding to run the func multiple times since its no longer syncronous

HotaruBlaze avatar Aug 25 '25 16:08 HotaruBlaze