timeline

package
v4.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

timeline

timeline is a package that provides functionality for easily implementing social scene application such as IM app, feed stream app.

timeline is based on TableStore timeline model.

Installation

$ go get github.com/aliyun/aliyun-tablestore-go-sdk

Sample

  • im application demo:
$ cd timeline/sample/im
$ go run main.go im.go
  • feed stream demo:
$ cd timeline/sample/feed
$ go run main.go feed.go

Benchmark

VM OS: Aliyun Linux 17.1 64bit

VM Configuration: 4 CPU, 8 GB RAM.

GO VERSION: 1.10.3 linux/amd64

Timeline Message Size: almost 220 bytes

  • on TableStore SSD High-performance instance
$ cd timeline
$ go test -bench=. -benchtime=10s -test.cpu=12
goos: linux
goarch: amd64
pkg: github.com/aliyun/aliyun-tablestore-go-sdk/timeline
BenchmarkTmLine_BatchStore_Concurrent-12                       	   10000	   1737993 ns/op
BenchmarkTmLine_BatchStore_WriteSpread-12                      	     100	 127729883 ns/op
BenchmarkTmLine_BatchStore_WriteSpread_IgnoreMessageLost-12    	     200	  80166859 ns/op
PASS
  • on TableStore Capacity instance
$ cd timeline
$ go test -bench=. -benchtime=10s -test.cpu=12
goos: linux
goarch: amd64
pkg: github.com/aliyun/aliyun-tablestore-go-sdk/timeline
BenchmarkTmLine_BatchStore_Concurrent-12                       	   10000	   1791522 ns/op
BenchmarkTmLine_BatchStore_WriteSpread-12                      	     100	 124597783 ns/op
BenchmarkTmLine_BatchStore_WriteSpread_IgnoreMessageLost-12    	     200	  83780501 ns/op

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMisuse     = errors.New("misuse")
	ErrUnexpected = errors.New("unexpected")
	ErrorDone     = errors.New("done")
)
View Source
var (
	DefaultFirstPk  = "TimelineId"
	DefaultSecondPk = "Sequence"

	MinTTL = 86400
)
View Source
var DefaultStreamAdapter = &StreamMessageAdapter{
	IdKey:        "Id",
	ContentKey:   "Content",
	TimestampKey: "Timestamp",
	AttrPrefix:   "Attr_",
}

Functions

This section is empty.

Types

type Api

type Api interface {
	Store(message Message) (int64, error)
	BatchStore(message Message) (*promise.Future, error)
	Update(sequenceId int64, message Message) error
	Load(sequenceId int64) (Message, error)
	Delete(sequenceId int64) error
	Scan(param *ScanParameter) *Iterator
}

type ColumnMap

type ColumnMap map[string]interface{}

func LoadColumnMap

func LoadColumnMap(attrs []*tablestore.AttributeColumn) ColumnMap

type DefaultStore

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

func (*DefaultStore) BatchStore

func (s *DefaultStore) BatchStore(id string, cols ColumnMap) *promise.Future

func (*DefaultStore) Close

func (s *DefaultStore) Close()

func (*DefaultStore) Delete

func (s *DefaultStore) Delete(id string, seq int64) error

func (*DefaultStore) Load

func (s *DefaultStore) Load(id string, seq int64) (ColumnMap, error)

func (*DefaultStore) Scan

func (s *DefaultStore) Scan(id string, param *ScanParameter) (map[int64]ColumnMap, int64, error)

func (*DefaultStore) Store

func (s *DefaultStore) Store(id string, cols ColumnMap) (int64, error)

func (*DefaultStore) Sync

func (s *DefaultStore) Sync() error

func (*DefaultStore) Update

func (s *DefaultStore) Update(id string, seq int64, cols ColumnMap) error

type Entry

type Entry struct {
	Sequence int64
	Message  Message
}

type Iterator

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

func NewIterator

func NewIterator(retCh chan *Entry, errCh chan error) (*Iterator, context.Context)

func (*Iterator) Close

func (i *Iterator) Close()

func (*Iterator) Next

func (i *Iterator) Next() (*Entry, error)

type Message

type Message interface{}

type MessageAdapter

type MessageAdapter interface {
	Marshal(msg Message) (ColumnMap, error)
	Unmarshal(cols ColumnMap) (Message, error)
}

type MessageStore

type MessageStore interface {
	Sync() error
	Store(id string, cols ColumnMap) (int64, error)
	BatchStore(id string, cols ColumnMap) *promise.Future
	Update(id string, seq int64, cols ColumnMap) error
	Load(id string, seq int64) (ColumnMap, error)
	Delete(id string, seq int64) error
	Scan(id string, param *ScanParameter) (map[int64]ColumnMap, int64, error)
	Close()
}

func NewDefaultStore

func NewDefaultStore(option StoreOption) (MessageStore, error)

type ScanParameter

type ScanParameter struct {
	From          int64
	To            int64
	MaxCount      int
	IsForward     bool
	ColToGet      []string
	Filter        tablestore.ColumnFilter
	BufChanSize   int
	ErrorChanSize int
}

type Schema

type Schema struct {
	FirstPk  string
	SecondPk string
}

type StoreOption

type StoreOption struct {
	Endpoint  string
	Instance  string
	TableName string
	AkId      string
	AkSecret  string

	Schema     *Schema
	TTL        int
	Throughput *tablestore.ReservedThroughput

	TableStoreConfig *tablestore.TableStoreConfig
	WriterConfig     *writer.Config
}

type StreamMessage

type StreamMessage struct {
	Id        string
	Content   interface{}
	Timestamp int64
	Attr      map[string]interface{}
}

type StreamMessageAdapter

type StreamMessageAdapter struct {
	IdKey        string
	ContentKey   string
	TimestampKey string
	AttrPrefix   string
}

func (*StreamMessageAdapter) Marshal

func (s *StreamMessageAdapter) Marshal(msg Message) (ColumnMap, error)

func (*StreamMessageAdapter) Unmarshal

func (s *StreamMessageAdapter) Unmarshal(cols ColumnMap) (Message, error)

type TmLine

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

func NewTmLine

func NewTmLine(id string, adapter MessageAdapter, store MessageStore) (*TmLine, error)

func (*TmLine) BatchStore

func (l *TmLine) BatchStore(message Message) (*promise.Future, error)

func (*TmLine) Delete

func (l *TmLine) Delete(sequenceId int64) error

func (*TmLine) Load

func (l *TmLine) Load(sequenceId int64) (Message, error)

func (*TmLine) Scan

func (l *TmLine) Scan(param *ScanParameter) *Iterator

func (*TmLine) Store

func (l *TmLine) Store(message Message) (int64, error)

func (*TmLine) Update

func (l *TmLine) Update(sequenceId int64, message Message) error

Directories

Path Synopsis
sample
im

Jump to

Keyboard shortcuts

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