Skip to content

Commit

Permalink
impl cache
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamka1 committed Jun 12, 2024
1 parent e5843e0 commit acfcf36
Show file tree
Hide file tree
Showing 12 changed files with 785 additions and 432 deletions.
617 changes: 444 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ arrow-schema = { version = "50" }
arrow-data = { version = "50" }
arrow-array = { version = "50" }

moka = { version = "0.12.7", features = ["sync"] }

# Make sure that transitive dependencies stick to disk_graph 50
[patch.crates-io]
arrow = { git = "https://github.com/apache/arrow-rs.git", tag = "50.0.0" }
Expand Down
49 changes: 31 additions & 18 deletions python/src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ use raphtory_graphql::{
algorithm_entry_point::AlgorithmEntryPoint, document::GqlDocument,
global_plugins::GlobalPlugins, vector_algorithms::VectorAlgorithms,
},
server_config::CacheConfig,
url_encode_graph, RaphtoryServer,
};
use reqwest::Client;
use serde_json::{json, Map, Number, Value as JsonValue};
use std::{
collections::HashMap,
path::PathBuf,
path::{Path, PathBuf},
thread,
thread::{sleep, JoinHandle},
time::Duration,
Expand Down Expand Up @@ -94,7 +95,7 @@ impl PyGlobalPlugins {
let graph = match &doc {
Document::Graph { name, .. } => {
vectorised_graphs.get(name).unwrap()
},
}
_ => panic!("search_graph_documents_with_scores returned a document that is not from a graph"),
};
(into_py_document(doc, graph, py), score)
Expand Down Expand Up @@ -220,20 +221,28 @@ impl PyRaphtoryServer {
#[pymethods]
impl PyRaphtoryServer {
#[new]
#[pyo3(signature = (graphs=None, graph_dir=None))]
#[pyo3(
signature = (work_dir, graphs = None, graph_paths = None, cache_capacity = 30, cache_ttl_seconds = 1800, cache_tti_seconds = 900)
)]
fn py_new(
work_dir: String,
graphs: Option<HashMap<String, MaterializedGraph>>,
graph_dir: Option<&str>,
graph_paths: Option<Vec<String>>,
cache_capacity: u64,
cache_ttl_seconds: u64,
cache_tti_seconds: u64,
) -> PyResult<Self> {
let server = match (graphs, graph_dir) {
(Some(graphs), Some(dir)) => Ok(RaphtoryServer::from_map_and_directory(graphs, dir)),
(Some(graphs), None) => Ok(RaphtoryServer::from_map(graphs)),
(None, Some(dir)) => Ok(RaphtoryServer::from_directory(dir)),
(None, None) => Err(PyValueError::new_err(
"You need to specify at least `graphs` or `graph_dir`",
)),
}?;

let graph_paths = graph_paths.map(|paths| paths.into_iter().map(PathBuf::from).collect());
let server = RaphtoryServer::new(
Path::new(&work_dir),
graphs,
graph_paths,
Some(CacheConfig {
capacity: cache_capacity,
ttl_seconds: cache_ttl_seconds,
tti_seconds: cache_tti_seconds,
}),
);
Ok(PyRaphtoryServer::new(server))
}

Expand Down Expand Up @@ -343,7 +352,9 @@ impl PyRaphtoryServer {
///
/// Arguments:
/// * `port`: the port to use (defaults to 1736).
#[pyo3(signature = (port = 1736, log_level="INFO".to_string(),enable_tracing=false,enable_auth=false))]
#[pyo3(
signature = (port = 1736, log_level = "INFO".to_string(), enable_tracing = false, enable_auth = false)
)]
pub fn start(
slf: PyRefMut<Self>,
port: u16,
Expand All @@ -363,7 +374,7 @@ impl PyRaphtoryServer {
.unwrap()
.block_on(async move {
let handler =
server.start_with_port(port, &log_level, enable_tracing, enable_auth);
server.start_with_port(port, Some(&log_level), enable_tracing, enable_auth);
let running_server = handler.await;
let tokio_sender = running_server._get_sender().clone();
tokio::task::spawn_blocking(move || {
Expand All @@ -387,7 +398,9 @@ impl PyRaphtoryServer {
///
/// Arguments:
/// * `port`: the port to use (defaults to 1736).
#[pyo3(signature = (port = 1736, log_level="INFO".to_string(),enable_tracing=false,enable_auth=false))]
#[pyo3(
signature = (port = 1736, log_level = "INFO".to_string(), enable_tracing = false, enable_auth = false)
)]
pub fn run(
slf: PyRefMut<Self>,
py: Python,
Expand Down Expand Up @@ -555,7 +568,7 @@ impl PyRunningRaphtoryServer {
///
/// Returns:
/// The `data` field from the graphQL response after executing the mutation.
#[pyo3(signature=(path, overwrite = false))]
#[pyo3(signature = (path, overwrite = false))]
fn load_graphs_from_path(
&self,
py: Python,
Expand Down Expand Up @@ -768,7 +781,7 @@ impl PyRaphtoryClient {
///
/// Returns:
/// The `data` field from the graphQL response after executing the mutation.
#[pyo3(signature=(path, overwrite = false))]
#[pyo3(signature = (path, overwrite = false))]
fn load_graphs_from_path(
&self,
py: Python,
Expand Down
5 changes: 5 additions & 0 deletions raphtory-benchmark/benches/arrow_algobench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn local_triangle_count_analysis(c: &mut Criterion) {
bench(&mut group, "local_triangle_count", None, |b| {
let g = raphtory::graph_loader::example::lotr_graph::lotr_graph();
let test_dir = TempDir::new().unwrap();
#[cfg(feature = "storage")]
let g = g.persist_as_disk_graph(test_dir.path()).unwrap();
let windowed_graph = g.window(i64::MIN, i64::MAX);

Expand Down Expand Up @@ -91,6 +92,7 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) {
}

let test_dir = TempDir::new().unwrap();
#[cfg(feature = "storage")]
let g = g.persist_as_disk_graph(test_dir.path()).unwrap();

let windowed_graph = g.window(0, 5);
Expand All @@ -108,6 +110,7 @@ pub fn graphgen_large_clustering_coeff(c: &mut Criterion) {
random_attachment(&graph, 500000, 4, Some(seed));

let test_dir = TempDir::new().unwrap();
#[cfg(feature = "storage")]
let graph = graph.persist_as_disk_graph(test_dir.path()).unwrap();

group.sampling_mode(SamplingMode::Flat);
Expand All @@ -134,6 +137,7 @@ pub fn graphgen_large_pagerank(c: &mut Criterion) {
random_attachment(&graph, 500000, 4, Some(seed));

let test_dir = TempDir::new().unwrap();
#[cfg(feature = "storage")]
let graph = graph.persist_as_disk_graph(test_dir.path()).unwrap();
group.sampling_mode(SamplingMode::Flat);
group.measurement_time(std::time::Duration::from_secs(20));
Expand All @@ -158,6 +162,7 @@ pub fn graphgen_large_concomp(c: &mut Criterion) {
let seed: [u8; 32] = [1; 32];
random_attachment(&graph, 500000, 4, Some(seed));
let test_dir = TempDir::new().unwrap();
#[cfg(feature = "storage")]
let graph = graph.persist_as_disk_graph(test_dir.path()).unwrap();

group.sampling_mode(SamplingMode::Flat);
Expand Down
1 change: 1 addition & 0 deletions raphtory-graphql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ url = { workspace = true }
base64-compat = { workspace = true }
time = { workspace = true }
reqwest = { workspace = true }
moka = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions raphtory-graphql/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[logging]
log_level = "INFO"

[cache]
capacity = 30
ttl_seconds = 1800
tti_seconds = 900
Loading

0 comments on commit acfcf36

Please sign in to comment.