Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Asynchronous query support #18

Open
mtijanic opened this issue Jan 18, 2018 · 3 comments · May be fixed by #1518
Open

SQL: Asynchronous query support #18

mtijanic opened this issue Jan 18, 2018 · 3 comments · May be fixed by #1518
Labels
RFE: plugin New feature or request

Comments

@mtijanic
Copy link
Member

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. A PrepareQuery() or ExecuteQuery() call automatically switch the active query as well.

@Liareth
Copy link
Member

Liareth commented Jan 18, 2018

+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.

@mtijanic mtijanic added RFE: plugin New feature or request and removed help wanted labels Feb 19, 2019
@virusman
Copy link
Member

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.

@virusman
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFE: plugin New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants