Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxPending gives decrease number #1501

Open
LeGamerDc opened this issue Dec 18, 2023 · 0 comments
Open

MaxPending gives decrease number #1501

LeGamerDc opened this issue Dec 18, 2023 · 0 comments
Labels
defect Suspected defect such as a bug or regression

Comments

@LeGamerDc
Copy link

Observed behavior

i run a benchmark of nats

func BenchmarkNatsT(b *testing.B) {
	nc, _ := nats.Connect("nats://127.0.0.1:4222", nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) {
		if errors.Is(err, nats.ErrSlowConsumer) {
			pm, pb, _ := sub.Pending()
			mpm, mpb, _ := sub.MaxPending()
			logger.Info("slow consumer", zap.Int("pending", pm), zap.Int("pendingBytes", pb),
				zap.Int("maxPending", mpm), zap.Int("maxPendingBytes", mpb))
		}
	}))
	sub, _ := nc.SubscribeSync("test")
	go func() {
		for i := 0; i < b.N; i++ {
			assert.Nil(b, nc.Publish("test", []byte("hello")))
		}
	}()
	for i := 0; i < b.N; i++ {
		_, _ = sub.NextMsg(time.Second)
	}
	pm, _, _ := sub.Pending()
	mpm, _, _ := sub.MaxPending()
	lpm, _, _ := sub.PendingLimits()
	fmt.Printf("%d/%d/%d\n", pm, mpm, lpm)
}

and see slow consumer log says pending=65536 and maxPending=65537. but, when benchmark ends, it give a mpm=6169, doesn't the maxPending should give biggest number in whole run?

Expected behavior

maxPending in the ends give 65537

Server and client version

nats-server --version
nats-server: v2.10.7

github.com/nats-io/nats.go v1.31.0 // indirect

Host environment

Mac with M1

Steps to reproduce

go test -bench=. -run=BenchmarkNatsT -count=1 -benchtime=1000000x

@LeGamerDc LeGamerDc added the defect Suspected defect such as a bug or regression label Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

1 participant