GithubHelp home page GithubHelp logo

Warm services watchdog about nox HOT 1 CLOSED

folex avatar folex commented on June 3, 2024
Warm services watchdog

from nox.

Comments (1)

swarna1101 avatar swarna1101 commented on June 3, 2024

It sounds like you are describing a system for dynamically pausing and unpausing services in order to improve the scalability of services-per-node. In this system, services can be paused by removing them without removing their disk state, and then started again on demand. The paused service queue would retain calls sent to the service before it is unpaused, and it would be possible to get the state of a service (paused, awake, or non-existent). Some services may be marked as unpausable, such as built-in services or services used by scheduled scripts.

To implement this system, you may want to consider the following steps:

  1. Implement a way to pause and unpause services by removing and starting them without removing their disk state.
  2. Implement a paused service queue to retain calls made to paused services.
  3. Implement a way to get the interface of a service without waking it up.
  4. Implement a way to get the state of a service (paused, awake, or non-existent).
  5. Mark some services as unpausable if necessary.

It is important to keep in mind that services should be ready to be restarted in the event of a node reboot, so they should be designed to handle being paused and unpaused. You may want to measure how long it takes to unpause and start a service to understand whether this approach is viable. It is also possible that you may need to cache compiled WASM code to improve performance.

In the documentation for your system, you should explain that services should be ready to be restarted in order to be compatible with the pausing and unpausing system. This will help users understand the requirements for using this feature.

use std::collections::HashMap;
use std::sync::{Arc, Mutex};

struct Service {
    // Other fields for the service go here...

    // Flag to indicate whether the service is paused
    paused: bool,
}

struct PausedServiceQueue {
    // Map of service ID to the calls made to the service while it was paused
    queue: HashMap<String, Vec<String>>,
}

impl PausedServiceQueue {
    fn new() -> Self {
        PausedServiceQueue {
            queue: HashMap::new(),
        }
    }

    fn add_call(&mut self, service_id: String, call: String) {
        self.queue.entry(service_id).or_default().push(call);
    }

    fn remove_calls(&mut self, service_id: &str) -> Vec<String> {
        self.queue.remove(service_id).unwrap_or_default()
    }
}

struct ServiceManager {
    services: HashMap<String, Arc<Mutex<Service>>>,
    paused_services: Arc<Mutex<PausedServiceQueue>>,
}

impl ServiceManager {
    fn new() -> Self {
        ServiceManager {
            services: HashMap::new(),
            paused_services: Arc::new(Mutex::new(PausedServiceQueue::new())),
        }
    }

    fn add_service(&mut self, service_id: String, service: Service) {
        self.services.insert(service_id, Arc::new(Mutex::new(service)));
    }

    fn pause_service(&mut self, service_id: &str) {
        let service = self.services.get_mut(service_id).unwrap();
        let mut service = service.lock().unwrap();
        service.paused = true;
    }

    fn unpause_service(&mut self, service_id: &str) {
        let service = self.services.get_mut(service_id

from nox.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.