No buffer space available (tcp.cpp:69) when setting SNDBUF and RCVBUF ZeroMQ, golang, MacOSX

huangapple go评论85阅读模式
英文:

No buffer space available (tcp.cpp:69) when setting SNDBUF and RCVBUF ZeroMQ, golang, MacOSX

问题

我已经安装了zeromq:stable 4.1.4,并使用brew在MacOSX上进行了安装。我编写了一个简单的PUB/SUB程序来测试zeromq。但是当我使用--bufsize > 5(使用大小> 5MB的缓冲区)的标志运行示例程序时(go run go_zmq_pubsub.go --bufsize=6),它会抛出以下异常:

No buffer space available (tcp.cpp:69)
SIGABRT: abort
PC=0x7fff9911c286 m=0
signal arrived during cgo execution

以下是我用来测试zeromq4.x的程序:

package main

import (
	"fmt"
	"flag"
	"strconv"
	"sync"
	log "github.com/Sirupsen/logrus"
	zmq "github.com/pebbe/zmq4"
	"time"
)

var _ = fmt.Println

func main(){
	var port int
	var bufsize int
	flag.IntVar(&port, "port", 7676, "server's zmq tcp port")
	flag.IntVar(&bufsize, "bufsize", 0, "socket kernel buffer size")

	flag.Parse();

	publisher, err := zmq.NewSocket(zmq.PUB)
	if(err != nil) {
		log.Fatal(err)
	}

	//set publisher kernel transmit buffer size
	//convert into bytes
	if err := publisher.SetSndbuf(bufsize * 1000000); err != nil {
		log.Fatal(err)
	}

	defer publisher.Close()
	publisher.Bind("tcp://*:" + strconv.Itoa(port))

	//SETUP subscriber
	subscriber, err := zmq.NewSocket(zmq.SUB)
	if(err != nil) {
		log.Fatal(err)
	}

	//set subscriber kernel receive buffer size
	if err := subscriber.SetRcvbuf(bufsize * 1000000); err != nil {
		log.Fatal(err)
	}

	defer subscriber.Close()
	subscriber.Connect("tcp://127.0.0.1:" + strconv.Itoa(port))
	subscriber.SetSubscribe("")

	var wg sync.WaitGroup
	wg.Add(2)

	idx := 0

	go func(wg *sync.WaitGroup) {
		//start streaming messages
		ticker := time.NewTicker(1 * time.Second)
		go func() {
			for {
				select {
				case <-ticker.C:
					_, err = publisher.Send("PKG:"+strconv.Itoa(idx), 0)

					idx++;

					if(err != nil) {
						log.Error(err)
					}
				}
			}
		}()
	}(&wg)


	//receiver
	go func(wg *sync.WaitGroup) {
		go func(){
			for {
				payload, err := subscriber.Recv(0)
				_ = payload

				if err != nil {
					log.Error(err)
					break
				}

				//now sending into worker pool
				log.Info("RECEIVE:" + payload)
			}
		}()
	}(&wg)

	wg.Wait()
}

在从源代码构建的lib-zeromq上的Centos7上,上述代码可以正常工作。

不确定是由于libzeromq还是操作系统本身引起的问题。

谢谢。

英文:

I have zeromq: stable 4.1.4 installed using brew on MacOSX and have written a simple PUB/SUB program to test zeromq. But when I run the sample program using flags --bufsize > 5 (to use a buffer of size > 5MB) (go run go_zmq_pubsub.go --bufsize=6); it throws the following exception:

No buffer space available (tcp.cpp:69)
SIGABRT: abort
PC=0x7fff9911c286 m=0
signal arrived during cgo execution

Below is the program I used to test the zeromq4.x

package main
import (
&quot;fmt&quot;
&quot;flag&quot;
&quot;strconv&quot;
&quot;sync&quot;
log &quot;github.com/Sirupsen/logrus&quot;
zmq &quot;github.com/pebbe/zmq4&quot;
&quot;time&quot;
)
var _ = fmt.Println
func main(){
var port int
var bufsize int
flag.IntVar(&amp;port, &quot;port&quot;, 7676, &quot;server&#39;s zmq tcp port&quot;)
flag.IntVar(&amp;bufsize, &quot;bufsize&quot;, 0, &quot;socket kernel buffer size&quot;)
flag.Parse();
publisher, err := zmq.NewSocket(zmq.PUB)
if(err != nil) {
log.Fatal(err)
}
//set publisher kernel transmit buffer size
//convert into bytes
if err := publisher.SetSndbuf(bufsize * 1000000); err != nil {
log.Fatal(err)
}
defer publisher.Close()
publisher.Bind(&quot;tcp://*:&quot; + strconv.Itoa(port))
//SETUP subscriber
subscriber, err := zmq.NewSocket(zmq.SUB)
if(err != nil) {
log.Fatal(err)
}
//set subscriber kernel receive buffer size
if err := subscriber.SetRcvbuf(bufsize * 1000000); err != nil {
log.Fatal(err)
}
defer subscriber.Close()
subscriber.Connect(&quot;tcp://127.0.0.1:&quot; + strconv.Itoa(port))
subscriber.SetSubscribe(&quot;&quot;)
var wg sync.WaitGroup
wg.Add(2)
idx := 0
go func(wg *sync.WaitGroup) {
//start streaming messages
ticker := time.NewTicker(1 * time.Second)
go func() {
for {
select {
case &lt;-ticker.C:
_, err = publisher.Send(&quot;PKG:&quot;+strconv.Itoa(idx), 0)
idx++;
if(err != nil) {
log.Error(err)
}
}
}
}()
}(&amp;wg)
//receiver
go func(wg *sync.WaitGroup) {
go func(){
for {
payload, err := subscriber.Recv(0)
_ = payload
if err != nil {
log.Error(err)
break
}
//now sending into worker pool
log.Info(&quot;RECEIVE:&quot; + payload)
}
}()
}(&amp;wg)
wg.Wait()
}

On Centos7 with lib-zeromq built from source, the above code works without problem.

Not sure if it's due to libzeromq or the OS itself.

Thanks.

答案1

得分: 1

缓冲区大小大于5MB是没有意义的。超过相关链路的带宽-延迟乘积的任何空间都是浪费的。

适度降低你的要求。

英文:

A buffer size of > 5MB is pointless. Anything beyond the bandwidth-delay product of the link concerned is wasted space.

Moderate your requirements.

huangapple
  • 本文由 发表于 2016年2月9日 15:35:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/35286317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定