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

Improvement cache size calculation and health method #198

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions rpc-server/src/health.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use crate::config::ServerContext;
use crate::utils::friendly_memory_size_format;
use actix_web::Responder;
use sysinfo::{System, SystemExt};

#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct RPCHealthStatusResponse {
total_memory: String,
used_memory: String,
available_memory: String,

blocks_in_cache: usize,
max_blocks_cache_size: String,
current_blocks_cache_size: String,
Expand All @@ -26,9 +21,6 @@ pub struct RPCHealthStatusResponse {

impl RPCHealthStatusResponse {
pub async fn new(server_context: &ServerContext) -> Self {
let sys = System::new_all();
let total_memory = sys.total_memory();
let used_memory = sys.used_memory();
let blocks_cache = server_context.blocks_cache.read().await;
let contract_code_cache = server_context.contract_code_cache.read().await;
let compiled_contract_code_cache = server_context
Expand All @@ -37,10 +29,6 @@ impl RPCHealthStatusResponse {
.read()
.await;
Self {
total_memory: friendly_memory_size_format(total_memory as usize),
used_memory: friendly_memory_size_format(used_memory as usize),
available_memory: friendly_memory_size_format((total_memory - used_memory) as usize),

blocks_in_cache: blocks_cache.len(),
max_blocks_cache_size: friendly_memory_size_format(blocks_cache.max_size()),
current_blocks_cache_size: friendly_memory_size_format(blocks_cache.current_size()),
Expand Down Expand Up @@ -73,6 +61,6 @@ impl RPCHealthStatusResponse {

/// Rpc server status
#[actix_web::get("/health")]
pub(crate) async fn get_health_status(data: actix_web::web::Data<ServerContext>) -> impl Responder {
actix_web::web::Json(RPCHealthStatusResponse::new(&data).await)
pub(crate) async fn get_health_status() -> impl Responder {
actix_web::web::Json(serde_json::json!({"status": "ok"}))
}
4 changes: 3 additions & 1 deletion rpc-server/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ pub(crate) async fn calculate_contract_code_cache_sizes(
limit
}
} else {
available_memory
// half of available memory for caching `compiled_contracts` and `contract_code`.
// If you need more memory you can set the limit_memory_cache in the configuration file.
available_memory / 2
};

(mem_cache_size - block_cache_size) / 2 // divide on 2 because we have 2 caches: compiled_contracts and contract_code
Expand Down
Loading