DreamWeave-MP / CoreScripts

The serverside Lua scripts used to implement core functionality in S3MP.
MIT License
0 stars 1 forks source link

Multithreading #8

Open magicaldave opened 1 year ago

magicaldave commented 1 year ago

A previous version of tes3mp includes an async branch which may be of interest to @YvanCywan , some additional details on the use case for multithreading could be useful as well.

Server load is generally pretty light so I'd like to understand why this work was done to begin with and whether it's truly beneficial.

https://github.com/uramer/CoreScripts

YvanCywan commented 1 year ago

Urm's CoreScripts is not the official, it implements async through Lua's coroutines, which is a completely viable solution that we could use.

YvanCywan commented 11 months ago

I've performed some research, looking into how FiveM and Uramer handles coroutines.

We need a simple wrapped for creating threads, a scheduler (automated execution and resumption of coroutines) and a set of timers. We would usually be able to do this with the "effil" Lua package, but it does not seem to want to build on my system. However, this feature for asynchronous code will take a while. It will also require exhaustive testing.

I suggest we break this down into 3 or 4 smaller issues.

SaintMercury commented 9 months ago

I think I had issues building effil on newer versions of msvc, though, I was fairly naive at the time. I could try again and possibly track the issue and hopefully get a build/release for it for us to personally use.

Effil was pretty promising when I looked at it, and fairly simple. It also depends on how the threading model would work.

I present that we do somethink like a job scheduler where you pass a function that accepts an argument of tes3mp object o puill and send whatever data you need.

ScheduleTask(function (tes3mp)
   tes3mp.LogMessage(1, "Executed Task")
end)

We'd probably need something for triggering event handlers too obvs, but this was my theory on getting it to work when I experimented with it.

SaintMercury commented 9 months ago

I'd also like to add that async =/= concurrent =/ parallel.

Async might get some benefit, but it does require writing scripts to somewhat aggressively use yield, where as parallelism we can probably try to keep most scripting still just basic-ish lua.