server

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2017 License: GPL-3.0 Imports: 21 Imported by: 0

README

server Build Status codecov

Getting Started

See the Getting Started guide.

Development

Ensure you have GOPATH set up and Docker installed.

Make sure you the repo is located properly inside GOPATH:

mkdir -p $GOPATH/src/github.com/bblfsh
cd $GOPATH/src/github.com/bblfsh
git clone https://github.com/bblfsh/server.git
cd server
Building From Source

Build with:

$ make dependencies
$ make build
Running Tests

Run tests with:

$ make test

License

GPLv3, see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPoolTimeout is the time a request to the DriverPool can wait
	// before getting a driver assigned.
	DefaultPoolTimeout = time.Second * 5

	// DefaultMaxInstancesPerDriver is the maximum number of instances of
	// the same driver which can be launched following the default
	// scaling policy (see DefaultScalingPolicy()).
	DefaultMaxInstancesPerDriver = runtime.NumCPU()
)
View Source
var (
	ErrMissingDriver    = errors.NewKind("missing driver for language %s")
	ErrRuntime          = errors.NewKind("runtime failure")
	ErrAlreadyInstalled = errors.NewKind("driver already installed: %s (image reference: %s)")
)

Functions

func GetLanguage

func GetLanguage(filename string, content []byte) string

GetLanguage detects the language of a file and returns it in a normalized form.

Types

type Driver

type Driver interface {
	protocol.Parser
	io.Closer
}

Driver is a client to communicate with a driver. It provides the parser interface and is closeable.

func ExecDriver

func ExecDriver(r *runtime.Runtime, img runtime.DriverImage) (Driver, error)

ExecDriver executes a new driver using the given runtime and driver image and returns a Driver instance for it. The Driver instance returned by this method is not thread-safe.

type DriverPool

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

DriverPool controls a pool of drivers and balances requests among them, ensuring each driver does not get concurrent requests. The number of driver instances in the driver pool is controlled by a ScalingPolicy.

func StartDriverPool

func StartDriverPool(scaling ScalingPolicy, timeout time.Duration, new func() (Driver, error)) (*DriverPool, error)

StartDriverPool creates and starts a new DriverPool. It takes as parameters the ScalingPolicy, the timeout for requests before getting a driver assigned, and a function to create driver instances.

func (*DriverPool) Close

func (dp *DriverPool) Close() error

Close closes the driver pool, including all its underlying driver instances.

func (*DriverPool) Parse added in v0.5.0

Parse processes a ParseRequest. It gets a driver from the pool and forwards the request to it. If all drivers are busy, it will return an error after the timeout passes. If the DriverPool is closed, an error will be returned.

type ScalingPolicy

type ScalingPolicy interface {
	// Scale takes the number of total instances and the load. The load is
	// the number of request waiting or, there is none, it is a negative
	// value indicating how many instances are ready.
	Scale(total, load int) int
}

ScalingPolicy specifies whether instances should be started or stopped to cope with load.

func AIMD

func AIMD(add int, mul float64) ScalingPolicy

AIMD returns a ScalingPolicy of additive increase / multiplicative decrease. Increases are of min(add, load). Decreases are of (ready / mul).

func DefaultScalingPolicy

func DefaultScalingPolicy() ScalingPolicy

DefaultScalingPolicy returns a new instance of the default scaling policy. Instances returned by this function should not be reused.

func MinMax

func MinMax(min, max int, p ScalingPolicy) ScalingPolicy

MinMax wraps a ScalingPolicy and applies a minimum and maximum to the number of instances.

func MovingAverage

func MovingAverage(window int, p ScalingPolicy) ScalingPolicy

MovingAverage computes a moving average of the load and forwards it to the underlying scaling policy. This policy is stateful and not thread-safe, do not reuse its instances for multiple pools.

type Server

type Server struct {

	// Transport to use to fetch driver images. Defaults to "docker".
	// Useful transports:
	// - docker: uses Docker registries (docker.io by default).
	// - docker-daemon: gets images from a local Docker daemon.
	Transport string
	// contains filtered or unexported fields
}

Server is a Babelfish server.

func NewServer

func NewServer(v string, r *runtime.Runtime, overrides map[string]string) *Server

func (*Server) AddDriver

func (s *Server) AddDriver(lang string, img string) error

func (*Server) Close

func (s *Server) Close() error

func (*Server) Driver

func (s *Server) Driver(lang string) (Driver, error)

func (*Server) Parse added in v0.5.0

func (*Server) Serve

func (s *Server) Serve(listener net.Listener, maxMessageSize int) error

func (*Server) Version added in v0.7.0

Directories

Path Synopsis
cmd
Package runtime provide the runtime environment to execute the bblfsh drivers The runtime is based on libcontainer allowing to the runtime run the drivers inside of a isolated lightweight container.
Package runtime provide the runtime environment to execute the bblfsh drivers The runtime is based on libcontainer allowing to the runtime run the drivers inside of a isolated lightweight container.

Jump to

Keyboard shortcuts

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