Giter Club home page Giter Club logo

flyline's Introduction

flyline

Fly multi-producer / multi-consumer channels for Go

A flyline buffer works similar to a standard Go channel with the following features:

  • It has a sync method. That means, you can wait for all after close buffer.
  • It is lock-free and thread-safe.
  • By default, it does not have a cap, you can use send filter to implement it.

Getting Started

Installing

To start using flyline, install Go and run go get:

$ go get github.com/pharosnet/flyline

This will retrieve the library.

Usage

It's easily to use, like standard Go channel.

ArrayBuffer (it's better than go channel)

// buffer.go
package main

import (
	"github.com/pharosnet/flyline"
	"time"
	"context"
)

func main() {
	buf := flyline.NewArrayBuffer(1024*16)
	buf.Send(time.Now())
	value, ok := buf.Recv()
	recvTime := time.Time{}
	flyline.ValueScan(value, &recvTime)
	println(recvTime)
	// close buffer
	buf.Close()
	// change ctx to timeout, if sync with timeout. 
	buf.Sync(context.Background())
}
$ go run buffer.go 

QueueBuffer

// buffer.go
package main

import (
	"github.com/pharosnet/flyline"
	"time"
	"context"
)

func main() {
	buf := flyline.NewQueueBuffer()
	buf.Send(time.Now())
	value, ok := buf.Recv()
	recvTime := time.Time{}
	flyline.ValueScan(value, &recvTime)
	println(recvTime)
	// close buffer
	buf.Close()
	// change ctx to timeout, if sync with timeout. 
	buf.Sync(context.Background())
}
$ go run buffer.go 

Benchmarks

Each of the following benchmark tests sends an incrementing sequence message from one goroutine to another. The receiving goroutine asserts that the message is received is the expected incrementing sequence value. Any failures cause a panic. Unless otherwise noted, all tests were run using GOMAXPROCS=2.

MacBook Pro 13" Retina, Mid 2015
  • CPU: Intel Core i5 @ 2.70 Ghz
  • Operation System: OS X 10.13.4
  • Go Runtime: Go 1.10.0
  • Go Architecture: amd64
Scenario Per Operation Time
Channels: Buffered, Non-blocking, GOMAXPROCS=1 19.7 ns/op
Channels: Buffered, Non-blocking, GOMAXPROCS=2 21.0 ns/op
Channels: Buffered, Non-blocking, GOMAXPROCS=3, Contended Write 110.0 ns/op
ArrayBuffer: Buffered, Non-blocking, GOMAXPROCS=1 11.9 ns/op
ArrayBuffer: Buffered, Non-blocking, GOMAXPROCS=2 7.14 ns/op
ArrayBuffer: Buffered, Non-blocking, GOMAXPROCS=3, Contended Write 11.9 ns/op

Contact

Ryougi Nevermore @ryougi

License

flyline source code is available under the GPL-3 License.

flyline's People

Contributors

ryouginevermore avatar

Stargazers

Gábor Nagymajtényi avatar Nikita Zhenev avatar  avatar Mauro Delazeri avatar

Watchers

James Cloos avatar

Forkers

ryouginevermore

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.