codexec

package
v0.0.0-...-8eed94c Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MountSource = "target"
	MountTarget = "/target"
)
View Source
const ProgramFilename = "Main"

Variables

View Source
var (
	Golang     = newLanguageCharacteristic("golang", "/usr/local/go/bin/go run Main.go", ".go")
	Python3    = newLanguageCharacteristic("python3", "python3 Main.py", ".py")
	Javascript = newLanguageCharacteristic("javascript", "nodejs Main.js", ".js")
	NodeJS     = newLanguageCharacteristic("nodejs", "nodejs Main.js", ".js")
	Java8      = newLanguageCharacteristic("java8", "javac Main.java && java Main", ".java")
	C          = newLanguageCharacteristic("c", "gcc Main.c -o Main && ./Main", ".c")
	CPlusplus  = newLanguageCharacteristic("c++", "g++ Main.cpp -o Main && ./Main", ".cpp")
)

Functions

func WriteFile

func WriteFile(baseDir, filename, content string) (string, error)

Types

type Codexec

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

func New

func New(containerClient ContainerClient, hostConfig *container.HostConfig, write Write) *Codexec

func (*Codexec) Exec

func (c *Codexec) Exec(ctx context.Context, containerID string, info ExecutionInfo) (*ExecutionRes, error)

func (*Codexec) ExecOnce

func (c *Codexec) ExecOnce(ctx context.Context, info ExecutionInfo) (*ExecutionRes, error)

type Codexecutor

type Codexecutor interface {
	Exec(ctx context.Context, containerID string, info ExecutionInfo) (*ExecutionRes, error)
}

type ContainerBalancer

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

func NewContainerBalancer

func NewContainerBalancer(containerClient ContainerClient, containerPool *ContainerPool,
	hostConfig *container.HostConfig, executor Codexecutor) *ContainerBalancer

func (*ContainerBalancer) Balance

func (cb *ContainerBalancer) Balance(ticker *time.Ticker)

Balance get the snapshot of the containers average, min and max response times. According to containers response times decide to create new containers or delete the existing ones to not waste a resource. If there is no snapshot just took a snapshot and also limit the container creation and deletion to the min and max limits.

func (*ContainerBalancer) Exec

Exec get the execution info and find the next container to use that container to execute the programming content when execution is done send response to client and start a goroutine to update the container status and metrics

func (*ContainerBalancer) FillPool

func (cb *ContainerBalancer) FillPool(ctx context.Context)

FillPool use container client to list all active containers and the fill the pool with the active containers

func (*ContainerBalancer) Shutdown

func (cb *ContainerBalancer) Shutdown(ctx context.Context)

type ContainerClient

type ContainerClient interface {
	Create(ctx context.Context, hostConfig *container.HostConfig) (string, error)
	Exec(ctx context.Context, id, workingDir string, cmd []string) (*rc.ExecRes, error)
	List(ctx context.Context) ([]string, error)
	ForceRemove(ctx context.Context, id string)
}

type ContainerNode

type ContainerNode struct {
	ID             string
	ExecutionCount int64
	AvgResTime     time.Duration
	MaxResTime     time.Duration
	MinResTime     time.Duration

	Prev *ContainerNode
	Next *ContainerNode
}

ContainerNode node that stores the container id, next and prev and metrics information

type ContainerPool

type ContainerPool struct {
	Head    *ContainerNode
	Tail    *ContainerNode
	Curr    *ContainerNode
	Nodes   map[string]*ContainerNode
	Garbage map[string]*ContainerNode
}

ContainerPool stores the container nodes in a structured way Active container nodes stored in a Circular Doubly Linked List and Nodes map Passive, Exited container nodes are removed from CDLL and stored in garbage

func NewContainerPool

func NewContainerPool() *ContainerPool

func (*ContainerPool) Add

func (p *ContainerPool) Add(id string)

func (*ContainerPool) Get

func (p *ContainerPool) Get() *ContainerNode

func (*ContainerPool) Remove

func (p *ContainerPool) Remove(id string)

type ExecutionInfo

type ExecutionInfo struct {
	Lang    string
	Content string
	Args    []string
}

func (ExecutionInfo) Command

func (info ExecutionInfo) Command() []string

type ExecutionRes

type ExecutionRes struct {
	Output        string
	ExecutionTime time.Duration
}

type LanguageCharacteristic

type LanguageCharacteristic struct {
	Name      string
	Commands  string
	Extension string
}

func (LanguageCharacteristic) Filename

func (c LanguageCharacteristic) Filename() string

type SupportedLanguages

type SupportedLanguages map[string]LanguageCharacteristic

func (SupportedLanguages) Get

func (SupportedLanguages) IsSupported

func (s SupportedLanguages) IsSupported(lang string) bool

type Write

type Write func(baseDir, filename, content string) (string, error)

Jump to

Keyboard shortcuts

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