executor

package module
v0.0.0-...-e27b21c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 24 Imported by: 0

README

Task executor

The MECAnywhere agent module on a host to execute offloaded computations.

Integration

It receives the task definition including the image id, resource limit and the input in a json. The resource limit is expressed in CPU core count and MB of RAM.

{
  "id": "task-name",
  "resource": {"cpu":1, "mem":128}
  "input": "input accepted by the task codes"
}

build

Build the docker image with: docker build -t mecanywhere-executor -f docker/Dockerfile .

launch

create the virtual network on which mecanywhere will be launched and allocate a subnet for use

docker network create --subnet 172.18.0.0/16 mecanywhere

launch the executor

docker run --name mecanywhere_executor_test -v /var/run/docker.sock:/var/run/docker.sock --net=mecanywhere --ip=172.18.0.255 mecanywhere-executor:latest

test

send a curl request to invoke the sample task

curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "yourDockerAccount/sampleserver:latest", "input": "{\"name\": \"sbip\"}"}'
curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "yourDockerAccount/sampleserver:latest", "resource": {"cpu":1, "mem":128}, "input": "{\"name\": \"sbip\"}"}' -v

for non-linux machines

change the subnet mask to any other available one

docker network create --subnet 173.18.0.0/16 mecanywhere
docker run --name mecaanywhere_executor_test -v /var/run/docker.sock:/var/run/docker.sock --net=mecanywhere --ip=173.18.0.255 -p 2591:2591 mecanywhere-executor:latest
curl http://localhost:2591 -X POST -H "Content-Type: application/json" -d '{"id": "yourDockerAccount/sampleserver:latest", "input": "{\"name\": \"sbip\"}"}'

for host with GPU, shall pass --gpus=all to the mecanywhere-executor. (or pass selected gpus for mecanywhere to use, for example, --gpus='"device=1,2,3"')

docker run --name mecaanywhere_executor_test --gpus=all  -v /var/run/docker.sock:/var/run/docker.sock  -v <gpu-enabled-config-file>:/app/mecanywhere_executor.yaml  --net=mecanywhere --ip=172.18.0.255 -p 2591:2591 mecanywhere-executor:latest

Retrieve stats

curl http://172.18.0.255:2591/stats

Provide resource limit for the task

curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "hugy718/goserver:v2", "resource": {"cpu":2, "mem":256}, "input": "{\"name\": \"sbip\"}"}'

Pick the microVM runtime if the host has it.

curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "hugy718/sample:v1","runtime": "microVM", "resource": {"cpu":1, "mem":128}, "input": "{\"name\": \"sbip\"}"}'

Specify GPU

curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "mecanywhere-python-task:1227", "resource": {"cpu":1, "mem":256, "use_gpu": true, "gpu_count": 3}, "input": "{\"name\": \"sbip\"}"}'

use sgx

curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "sgx-task:latest", "resource": {"cpu":2, "mem":256}, "input": "{\"value\": \"sbip\"}", "use_sgx": true}'

Perform RA then send encrypted request

curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "mock-sgx-task:latest", "resource": {"cpu":2, "mem":256}, "input": "SGXRAREQUEST", "use_sgx": true}'
curl http://172.18.0.255:2591 -X POST -H "Content-Type: application/json" -d '{"id": "mock-sgx-task:latest", "resource": {"cpu":2, "mem":256}, "input": "{\"value\": \"<the-encrypted-task-input>\"}", "use_sgx": true}'

Can use the mecanywhere sample repo sgx task direct client to interact with a running mock server task to get a valid encryted input sample for testing.

Documentation

Index

Constants

View Source
const (
	SGXBindDevice = "/dev/sgx/enclave"
	SGXBindAesmd  = "/var/run/aesmd"
)
View Source
const (
	TaskTypeMicroVM   = "microVM"
	TaskTypeContainer = "container"
)
View Source
const (
	SGXRAREQUEST = "SGXRAREQUEST"
)

Variables

View Source
var (
	ErrContainerFailedToStartInTime = errors.New("container failed to start in time")
	ErrInitEntryNotFound            = errors.New("container init entry not found")
	ErrFailedToDecodeTaskResponse   = errors.New("failed to decode task response")
)

Functions

func GetGPUCount

func GetGPUCount() (int, error)

func GetGPUModel

func GetGPUModel() (string, error)

assuming a machine has only one type of GPU

func GetTaskId

func GetTaskId(cfg TaskConfig) string

func InitGPUMonitor

func InitGPUMonitor() error

func NewResourceManager

func NewResourceManager(totalCPU float64, totalMem int, hasGPU bool) *resourceManager

func NewResourceMonitor

func NewResourceMonitor(hasGPU bool) *resourceMonitor

func ShutdownGPUMonitor

func ShutdownGPUMonitor() error

Types

type DockerTask

type DockerTask struct {
	// contains filtered or unexported fields
}

func NewDockerTask

func NewDockerTask(taskId string, cfg TaskConfig, cli *client.Client) *DockerTask

func (*DockerTask) CleanUp

func (t *DockerTask) CleanUp() error

func (*DockerTask) Execute

func (t *DockerTask) Execute(ctx context.Context, input []byte) ([]byte, error)

pass the input to the container

func (*DockerTask) GetId

func (t *DockerTask) GetId() string

func (*DockerTask) GetResource

func (t *DockerTask) GetResource() ResourceLimit

func (*DockerTask) Init

func (t *DockerTask) Init(ctx context.Context, _ string, _ int, gpus []int) error

start the container which should run a server to replace with using docker bridge network only

type DockerTaskFactory

type DockerTaskFactory struct {
	// contains filtered or unexported fields
}

func NewDockerTaskFactory

func NewDockerTaskFactory(cli *client.Client) *DockerTaskFactory

func (*DockerTaskFactory) Build

func (f *DockerTaskFactory) Build(taskId string, cfg TaskConfig) (Task, error)

type GPUUtil

type GPUUtil struct {
	// contains filtered or unexported fields
}

func GetGPUUtilization

func GetGPUUtilization() ([]GPUUtil, error)

type LocalDockerRepo

type LocalDockerRepo struct {
	// contains filtered or unexported fields
}

func NewLocalDockerRepo

func NewLocalDockerRepo(cli *client.Client) *LocalDockerRepo

func (*LocalDockerRepo) Exists

func (r *LocalDockerRepo) Exists(id, version string) (bool, error)

func (*LocalDockerRepo) Fetch

func (r *LocalDockerRepo) Fetch(id, remote, version string) error

type MecaExecutor

type MecaExecutor struct {
	// contains filtered or unexported fields
}

func NewMecaExecutorFromConfig

func NewMecaExecutorFromConfig(cfg MecaExecutorConfig) *MecaExecutor

func (*MecaExecutor) Execute

func (meca *MecaExecutor) Execute(ctx context.Context, taskCfg TaskConfig, input []byte) ([]byte, error)

func (*MecaExecutor) Pause

func (meca *MecaExecutor) Pause()

func (*MecaExecutor) Start

func (meca *MecaExecutor) Start()

will launch cleaner goroutine to remove tasks after timeout

func (*MecaExecutor) Stats

func (meca *MecaExecutor) Stats() ResourceStats

func (*MecaExecutor) Stop

func (meca *MecaExecutor) Stop()

func (*MecaExecutor) UnPause

func (meca *MecaExecutor) UnPause()

func (*MecaExecutor) UpdateConfig

func (meca *MecaExecutor) UpdateConfig(cfg MecaExecutorConfigReq) (string, error)

type MecaExecutorConfig

type MecaExecutorConfig struct {
	Type           string    `yaml:"type"`
	Timeout        int       `yaml:"timeout"`
	Cpu            float64   `yaml:"cpu"`
	Mem            int       `yaml:"mem"`
	HasGPU         bool      `yaml:"has_gpu"`
	MicroVMRuntime string    `yaml:"microVM_runtime"`
	SGX            SGXConfig `yaml:"sgx"`
}

func ParseMecaExecutorConfig

func ParseMecaExecutorConfig(filename string) (MecaExecutorConfig, error)

type MecaExecutorConfigReq

type MecaExecutorConfigReq struct {
	Timeout        int     `json:"timeout"`
	Cpu            float64 `json:"cpu" binding:"required,gt=0.0"`
	Mem            int     `json:"mem" binding:"required,gt=0"`
	HasGPU         int     `json:"has_gpu"`
	MicroVMRuntime string  `json:"microVM_runtime"`
}

type MecaRequestHandle

type MecaRequestHandle struct {
	// contains filtered or unexported fields
}

func NewMecaRequestHandle

func NewMecaRequestHandle(ctx context.Context, taskCfg TaskConfig, input []byte) *MecaRequestHandle

func (*MecaRequestHandle) Done

func (h *MecaRequestHandle) Done()

func (*MecaRequestHandle) Wait

func (h *MecaRequestHandle) Wait()

type ResourceLimit

type ResourceLimit struct {
	CPU      int64 `json:"cpu"` // core
	MEM      int64 `json:"mem"` // MB
	UseGPU   bool  `json:"use_gpu"`
	GPUCount int64 `json:"gpu_count"`
}

func (ResourceLimit) String

func (l ResourceLimit) String() string

type ResourceManager

type ResourceManager interface {
	Start() bool
	Stop()
	UpdateConfig(cpu float64, mem int) string
	Reserve(cpu float64, mem int) error
	Release(cpu float64, mem int) error
	GetMaxCPUAndMem() (float64, uint64)
	GetGPUCount() int
	ReserveGPU(count int, utilLimit int) ([]int, error)
	ReleaseGPU([]int) error
	Stats() ResourceStats
}

controls the allocation of resources to tasks.

type ResourceMonitor

type ResourceMonitor interface {
	Start() bool            // start monitoring
	Stop()                  // stop monitoring
	GetCPU() int            // in core count
	GetMEM() int            // in MB
	GetCPUUsed() float64    // in core count
	GetMEMUsed() float64    // in MB
	GetCPUAvail() float64   // in core count
	GetMEMAvail() float64   // in MB
	GetGPUCount() int       // in count
	GetGPUModel() string    // in string
	GetGPUUtils() []GPUUtil // in list of GPUUtil (% pair)
}

monitor the availble resource on the host

type ResourceStats

type ResourceStats struct {
	TotalCPU    int     `json:"total_cpu"`     // core
	TotalMEM    int     `json:"total_mem"`     // MB
	UsedCPU     float64 `json:"used_cpu"`      // %
	UsedMEM     float64 `json:"used_mem"`      // %
	TaskCPU     float64 `json:"task_cpu"`      // core
	TaskMEM     int     `json:"task_mem"`      // MB
	TaskUsedCPU float64 `json:"task_used_cpu"` // %
	TaskUsedMEM float64 `json:"task_used_mem"` // %
	GPUModel    string  `json:"gpu_model"`
	TaskGPU     int     `json:"task_gpu"`      // count
	TaskUsedGPU int     `json:"task_used_gpu"` // count
}

func (*ResourceStats) IsEmpty

func (rs *ResourceStats) IsEmpty() bool

type SGXConfig

type SGXConfig struct {
	Enable    bool   `yaml:"enable"`
	SGXDevice string `yaml:"sgx_device"`
	AesmdPath string `yaml:"aesmd_path"`
}

type Task

type Task interface {
	GetId() string
	Init(ctx context.Context, config string, port int, gpus []int) error
	Execute(ctx context.Context, input []byte) ([]byte, error)
	GetResource() ResourceLimit // get resource limit of the task
	CleanUp() error
}

type TaskConfig

type TaskConfig struct {
	ImageId string        `json:"imageid"`
	Runtime string        `json:"runtime"`
	Rsrc    ResourceLimit `json:"resource_limit"`
	UseSGX  bool          `json:"use_sgx"`
	// contains filtered or unexported fields
}

func NewTaskConfig

func NewTaskConfig(id, rt string, rsrc ResourceLimit, sgx bool, sgxCfg *SGXConfig) TaskConfig

func (TaskConfig) String

func (c TaskConfig) String() string

type TaskFactory

type TaskFactory interface {
	// a task is specified by its id, the runtime and the amount of resource intended to use
	Build(taskId string, cfg TaskConfig) (Task, error)
}

type TaskRepo

type TaskRepo interface {
	Exists(id, version string) (bool, error)
	Fetch(id, remote, version string) error
}

version can be a hash

Directories

Path Synopsis
sample
go command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL