Skip to content

Commit

Permalink
Merge pull request #113 from cloudwego/release/v0.2.0
Browse files Browse the repository at this point in the history
chore: release v0.2.0
  • Loading branch information
joway authored Feb 22, 2022
2 parents 985eb36 + 509bada commit 10865ef
Show file tree
Hide file tree
Showing 20 changed files with 638 additions and 209 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# CloudWeGo-Netpoll

[中文](README_CN.md)

# Introduction
[![Release](https://img.shields.io/github/v/release/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/releases)
[![WebSite](https://img.shields.io/website?up_message=cloudwego&url=https%3A%2F%2Fwww.cloudwego.io%2F)](https://www.cloudwego.io/)
[![License](https://img.shields.io/github/license/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/blob/main/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/cloudwego/netpoll)](https://goreportcard.com/report/github.com/cloudwego/netpoll)
[![OpenIssue](https://img.shields.io/github/issues/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/issues)
[![ClosedIssue](https://img.shields.io/github/issues-closed/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/issues?q=is%3Aissue+is%3Aclosed)
![Stars](https://img.shields.io/github/stars/cloudwego/netpoll)
![Forks](https://img.shields.io/github/forks/cloudwego/netpoll)

## Introduction

[Netpoll][Netpoll] is a high-performance non-blocking I/O networking framework, which
focused on RPC scenarios, developed by [ByteDance][ByteDance].
Expand Down Expand Up @@ -31,7 +42,7 @@ using [Netpoll][Netpoll].

For more information, please refer to [Document](#document).

# Features
## Features

* **Already**
- [LinkBuffer][LinkBuffer] provides nocopy API for streaming reading and writing
Expand All @@ -54,7 +65,7 @@ For more information, please refer to [Document](#document).
* **Unsupported**
- Windows (operating system)

# Performance
## Performance

Benchmark should meet the requirements of industrial use.
In the RPC scenario, concurrency and timeout are necessary support items.
Expand All @@ -64,7 +75,7 @@ the performance of [Netpoll][Netpoll] and other frameworks under different condi

More benchmarks reference [kitex-benchmark][kitex-benchmark] and [hertz-benchmark][hertz-benchmark] (open source soon).

# Reference
## Reference

* [Official Website](https://www.cloudwego.io)
* [Getting Started](docs/guide/guide_en.md)
Expand All @@ -81,8 +92,8 @@ More benchmarks reference [kitex-benchmark][kitex-benchmark] and [hertz-benchmar
[Hertz]: https://github.com/cloudwego/hertz

[netpoll-benchmark]: https://github.com/cloudwego/netpoll-benchmark
[kitex-benchmark]: https://github.com/cloudwego/kitex
[hertz-benchmark]: https://github.com/cloudwego/hertz
[kitex-benchmark]: https://github.com/cloudwego/kitex-benchmark
[hertz-benchmark]: https://github.com/cloudwego/hertz-benchmark

[ByteDance]: https://www.bytedance.com
[Redis]: https://redis.io
Expand Down
23 changes: 17 additions & 6 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# CloudWeGo-Netpoll

[English](README.md)

# 简介
[![Release](https://img.shields.io/github/v/release/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/releases)
[![WebSite](https://img.shields.io/website?up_message=cloudwego&url=https%3A%2F%2Fwww.cloudwego.io%2F)](https://www.cloudwego.io/)
[![License](https://img.shields.io/github/license/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/blob/main/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/github.com/cloudwego/netpoll)](https://goreportcard.com/report/github.com/cloudwego/netpoll)
[![OpenIssue](https://img.shields.io/github/issues/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/issues)
[![ClosedIssue](https://img.shields.io/github/issues-closed/cloudwego/netpoll)](https://github.com/cloudwego/netpoll/issues?q=is%3Aissue+is%3Aclosed)
![Stars](https://img.shields.io/github/stars/cloudwego/netpoll)
![Forks](https://img.shields.io/github/forks/cloudwego/netpoll)

## 简介

[Netpoll][Netpoll] 是由 [字节跳动][ByteDance] 开发的高性能 NIO(Non-blocking I/O)
网络库,专注于 RPC 场景。
Expand All @@ -26,7 +37,7 @@ goroutine,大幅增加调度开销。此外,[net.Conn][net.Conn] 没有提

更多信息请参阅 [文档](#文档)

# 特性
## 特性

* **已经支持**
- [LinkBuffer][LinkBuffer] 提供可以流式读写的 nocopy API
Expand All @@ -49,15 +60,15 @@ goroutine,大幅增加调度开销。此外,[net.Conn][net.Conn] 没有提
* **不被支持**
- Windows(操作系统)

# 性能
## 性能

性能测试应满足工业级使用要求,在 RPC 场景下,并发请求、等待超时是必要的支持项。

我们提供了 [netpoll-benchmark][netpoll-benchmark] 项目用来长期追踪和比较 [Netpoll][Netpoll] 与其他框架在不同情况下的性能数据以供参考。

更多测试参考 [kitex-benchmark][kitex-benchmark][hertz-benchmark][hertz-benchmark] (即将开源)

# 参考
## 参考

* [官方网站](https://www.cloudwego.io)
* [使用文档](docs/guide/guide_cn.md)
Expand All @@ -74,8 +85,8 @@ goroutine,大幅增加调度开销。此外,[net.Conn][net.Conn] 没有提
[Hertz]: https://github.com/cloudwego/hertz

[netpoll-benchmark]: https://github.com/cloudwego/netpoll-benchmark
[kitex-benchmark]: https://github.com/cloudwego/kitex
[hertz-benchmark]: https://github.com/cloudwego/hertz
[kitex-benchmark]: https://github.com/cloudwego/kitex-benchmark
[hertz-benchmark]: https://github.com/cloudwego/hertz-benchmark

[ByteDance]: https://www.bytedance.com
[Redis]: https://redis.io
Expand Down
57 changes: 44 additions & 13 deletions connection_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (c *connection) Release() (err error) {
// c.operator.do competes with c.inputs/c.inputAck
if c.inputBuffer.Len() == 0 && c.operator.do() {
maxSize := c.inputBuffer.calcMaxSize()
// Set the maximum value of maxsize equal to mallocMax to prevent GC pressure.
if maxSize > mallocMax {
maxSize = mallocMax
}

if maxSize > c.maxSize {
c.maxSize = maxSize
}
Expand All @@ -137,6 +142,26 @@ func (c *connection) Len() (length int) {
return c.inputBuffer.Len()
}

// Until implements Connection.
func (c *connection) Until(delim byte) (line []byte, err error) {
var n, l int
for {
if err = c.waitRead(n + 1); err != nil {
// return all the data in the buffer
line, _ = c.inputBuffer.Next(c.inputBuffer.Len())
return
}

l = c.inputBuffer.Len()
i := c.inputBuffer.indexByte(delim, n)
if i < 0 {
n = l //skip all exists bytes
continue
}
return c.Next(i + 1)
}
}

// ReadString implements Connection.
func (c *connection) ReadString(n int) (s string, err error) {
if err = c.waitRead(n); err != nil {
Expand Down Expand Up @@ -242,9 +267,15 @@ func (c *connection) Read(p []byte) (n int, err error) {

// Write will Flush soon.
func (c *connection) Write(p []byte) (n int, err error) {
if !c.lock(flushing) {
return 0, Exception(ErrConnClosed, "when write")
}
defer c.unlock(flushing)

dst, _ := c.outputBuffer.Malloc(len(p))
n = copy(dst, p)
err = c.Flush()
c.outputBuffer.Flush()
err = c.flush()
return n, err
}

Expand All @@ -264,22 +295,20 @@ var barrierPool = sync.Pool{
},
}

// init arguments: conn is required, prepare is optional.
func (c *connection) init(conn Conn, prepare OnPrepare) (err error) {
// conn must be *netFD{}
c.checkNetFD(conn)

c.initFDOperator()
syscall.SetNonblock(c.fd, true)

// init initialize the connection with options
func (c *connection) init(conn Conn, opts *options) (err error) {
// init buffer, barrier, finalizer
c.readTrigger = make(chan struct{}, 1)
c.writeTrigger = make(chan error, 1)
c.bookSize, c.maxSize = block1k/2, pagesize
c.inputBuffer, c.outputBuffer = NewLinkBuffer(pagesize), NewLinkBuffer()
c.inputBarrier, c.outputBarrier = barrierPool.Get().(*barrier), barrierPool.Get().(*barrier)
c.setFinalizer()

c.initNetFD(conn) // conn must be *netFD{}
c.initFDOperator()
c.initFinalizer()

syscall.SetNonblock(c.fd, true)
// enable TCP_NODELAY by default
switch c.network {
case "tcp", "tcp4", "tcp6":
Expand All @@ -289,10 +318,12 @@ func (c *connection) init(conn Conn, prepare OnPrepare) (err error) {
if setZeroCopy(c.fd) == nil && setBlockZeroCopySend(c.fd, defaultZeroCopyTimeoutSec, 0) == nil {
c.supportZeroCopy = true
}
return c.onPrepare(prepare)

// connection initialized and prepare options
return c.onPrepare(opts)
}

func (c *connection) checkNetFD(conn Conn) {
func (c *connection) initNetFD(conn Conn) {
if nfd, ok := conn.(*netFD); ok {
c.netFD = *nfd
return
Expand All @@ -318,7 +349,7 @@ func (c *connection) initFDOperator() {
c.operator = op
}

func (c *connection) setFinalizer() {
func (c *connection) initFinalizer() {
c.AddCloseCallback(func(connection Connection) error {
c.stop(flushing)
c.netFD.Close()
Expand Down
Loading

0 comments on commit 10865ef

Please sign in to comment.