Comments (5)
Hi @finnbear - yep these functions need improvement...
If you take a look here: 52e8954#diff-c64155b4ec93e9f70ebc55225f93a2f293fda75403be40b085f75ea363e25fe5 there used to be a file called lib/src/exe/mod.rs
which contained the following code...
use executor::{Executor, Task};
use once_cell::sync::Lazy;
use std::future::Future;
use std::panic::catch_unwind;
pub fn spawn<T: Send + 'static>(future: impl Future<Output = T> + Send + 'static) -> Task<T> {
static GLOBAL: Lazy<Executor<'_>> = Lazy::new(|| {
std::thread::spawn(|| {
catch_unwind(|| {
futures::executor::block_on(GLOBAL.run(futures::future::pending::<()>()))
})
.ok();
});
Executor::new()
});
GLOBAL.spawn(future)
}
You could then send async futures/tasks to it...
crate::exe::spawn(async move { ..... }).await;
and that would be sent to a separate thread for the expensive computations. I only got rid of it because I was no longer using it for the query executor, but the executor
library is still being used in different ways (non-multi-threaded). The code above, basically just creates a single thread for dealing with the computationally intensive futures that shouldn't run in the main async runtime (as you noted).
The reason tokio
isn't included in the library is because of compiling to WASM.
Maybe we could reinstate exe
module in the lib/src
folder, and (after making the crypto functions async), send them to the executor thread to be processed?
from surrealdb.
Also @finnbear, I don't think there isn't a good reason for doing this for all of the crypto functions. Just in case?
from surrealdb.
On a side note, I couldn't work out a way of doing the argument checking...
Lines 41 to 46 in 3d83f08
for the async functions ...
Lines 187 to 199 in 3d83f08
so I ended up duplicating the argument checking code in each of the http functions...
Lines 58 to 61 in 3d83f08
If you work out a way of doing that nicely, then we can use the sae argument checking for the http
and crypto
functions!
from surrealdb.
Also @finnbear, currently that executor only sets up 1 separate thread, which is fine for the moment. We could (in the future) use the num_cpus
crate to start up the same number of threads for each CPU core (just like tokio does).
The ONE thing to remember is that threads can't be created in WASM, so sending the crypto functions to the executor thread needs to be behind the parallel
feature guard (and needs to work as it does at the moment if the parallel
feature is disabled).
from surrealdb.
Thank you for all the info, which should allow me to formulate a PR in the near future 😃
from surrealdb.
Related Issues (20)
- Bug: $session.ip is lost during login scope HOT 3
- Feature: Export to CSV
- Bug: Can't query using <future> fields HOT 1
- Feature: add dynamic args config for the http request body size and optimize the surrealdb client logic HOT 2
- Bug: weird results when comparating a field value and time::now()
- Bug: Performance regression of 10x over websocket from beta-9 to 1.0.0 release HOT 11
- Bug: ORDER BY should accept usage of field HOT 2
- Bug: `SELECT * ` in combination with `FETCH` always returns the full records for record links HOT 6
- Bug: LIVE QUERIES on NIGHLY responds with inconsisten datatypes. HOT 3
- Bug: cargo panic on launching the docker image (affects all images using chainguard base image) HOT 1
- Bug: Surreal SQL -e command is missing from installation? Cannot complete installation tutorial? HOT 1
- Feature: Record Links between Databases HOT 1
- Bug: Parsing after `FETCH` statement variables HOT 6
- Feature: Basic `object::` functions
- Bug: using UUIDs as object keys doesn't work for accessing the object
- Feature: Ability to parse compressed maps
- Feature: Query completion before EVENT trigger HOT 2
- Bug: `SELECT * FROM <number> true` has stopped working
- Bug: nonFLEXIBLE array of FLEXIBLE anys deletes the written data that's about to be created HOT 2
- Feature: Live query support in Rust SDK HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surrealdb.