Go Concurrency Programming Project.
An example project for book 'Go Programming & Concurrency in Practice' (《Go并发编程实战》).
The sample project for the second edition of this book is here.
An example project for book 'Go Programming & Concurrency in Practice'.
License: GNU General Public License v2.0
Go Concurrency Programming Project.
An example project for book 'Go Programming & Concurrency in Practice' (《Go并发编程实战》).
The sample project for the second edition of this book is here.
goc2p/src/multiproc/apipe/apipe.go
demo2 为何会阻塞住?
https://github.com/g0hacker/goc2p/blob/master/src/basic/map1/omap.go#L38
return omap.elemType == reflect.TypeOf(e)
this is better than
if reflect.TypeOf(e) != omap.elemType {
return false
}
return true
Otherwise, monitor might start running before scheduler is fully started and query those components which are not initialized. It will run into a panic.
code in basic/set
// 判断集合 one 是否是集合 other 的超集
func IsSuperset(one Set, other Set) bool {
if one == nil || other == nil {
return false
}
oneLen := one.Len()
otherLen := other.Len()
if oneLen == 0 || oneLen == otherLen {
return false
}
if oneLen > 0 && otherLen == 0 {
return true
}
for _, v := range other.Elements() {
if !one.Contains(v) {
return false
}
}
return true
}
Proper super set is not equivalent of super set.
In other words, if one == other, then one issuperset of other(just like Python set.issuperset method).
if oneLen == 0 || oneLen == otherLen {
return false
}
并发量 = 单个载荷的响应超时时间 / 载荷的发送间隔时间
1e9 / lps 代表了发送的间隔,
对这一段有疑问?
a) lps是发送频率可以理解,1e9 / lps 代表了发送的间隔 为什么这个可以作为发送间隔?
b)并发量 的公式 也是不理解?
另外再后续实现代码里,
func (gen *myGenerator) genLoad(throttle <-chan time.Time) {
callCount := uint64(0)
Loop:
for ; ; callCount++ {
select {
case <-gen.stopSign:
gen.handleStopSign(callCount)
break Loop
default:
}
gen.asyncCall()
if gen.lps > 0 {
select {
case <-throttle:
case <-gen.stopSign:
gen.handleStopSign(callCount)
break Loop
}
}
}
}
这里再start里其实只是一个goroutine启动,然后无限循环,这样的测试,其实每个发送请求之间并不是一起过去的,是一次循环一次循环出去的。那这个并发其实并不准确。为何不使用
for i =0 ; i < current ; i ++ {
go func() {
for {
//todo
}
}()
}
这样在启动起来之后,基本可以说同1s,有那么多goroutine 进行请求。
而上述循环中,不停开启goroutine,如果接口响应很快的话,基本是不可能有一个同一时间的压力
这里,我的理解是否有偏差,还望解答,谢谢。
如题
package map1
import (
"testing"
"reflect"
"fmt"
"encoding/json"
)
func Test2JSON(t *testing.T){
cmap := NewConcurrentMap(reflect.TypeOf(string("")), reflect.TypeOf(string("")))
cmap.Put("k1", "v1")
fmt.Printf("%v\n", cmap)
bytes, err := json.Marshal(cmap) // 无法将内部数据转成 JSON
if err == nil {
fmt.Println(string(bytes))
}else {
fmt.Printf("err = %v\n",err)
}
}
C:/Go\bin\go.exe test -v basic/map1 -run ^Test2JSON$
ConcurrentMap<string,string>{k1:v1}
{}
ok basic/map1 0.234s
func main() {
demo1()
fmt.Println()
demo2()
}
reproducing
func main() {
//demo1()
fmt.Println()
demo2()
time.Sleep(time.Seconds * 10)
}
Just sleep 10s. Meanwhile you can run ps -ef
. You can see [ps] <defunct>
regex := regexp.MustCompilePOSIX("([a-z])\1")
panic: regexp: CompilePOSIX(([a-z])\1
): error parsing regexp: invalid escape sequence: \1
这个语句会导致这个panic,golang似乎对正则支持不太友好,有什么好的方法吗?
https://github.com/g0hacker/goc2p/blob/master/src/basic/map1/cmap_test.go#L257
this is a redundant line
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.