Open mtijanic opened 6 years ago
+1. When I worked on Arelith, this was a real problem. We saw locks of up to 10 seconds rarely when executing a query while the database engine was to doing ... things.
I'm wondering if this could somehow be done via script parts and action
... Similar to DelayCommand
, but instead of a specified delay, it'd call the script part when the query completes.
Maybe hook CNWVirtualMachineCommands::ExecuteCommandActionDoCommand
to pop CVirtualMachineScript *
from the stack, store it and then add it back to the command stack when the command completes with object->AddDoCommandAction(pScript)
.
While an SQL query is running, the main server thread is suspended. It's not unheard of for queries to take seconds to complete, which causes huge lag spikes, and in extreme cases can even disconnect the clients.
We need a way to queue up a query on the Async thread, and register a callback nwscript to deal with the results afterwards.
Should wait for #5 first before implementing.
On the API side, we'll need to explicitly specify which query we're operating on (because now we can have multiple active queries).
Option 1: Pass the query ID manually to all functions. We can remain compatible with the existing API by having the default query ID of 0 (never a valid ID) refer to the last one used by nwscript. For existing usecases nothing changes, but script callbacks will need to manually specify the ID (which they'd get as a local var on OBJECT_SELF).
Option 2: Expose a
SetActiveQuery(int id)
to manually switch the states for the current script. APrepareQuery()
orExecuteQuery()
call automatically switch the active query as well.