Closed rbaethe closed 2 years ago
@rbaethe Is this a server issue or a client issue? This example is too complicated for just code, can you make a maven or gradle project in a repo that we can run?
Hi @scottf - thanks for the reply. I see in the console log, that the rate limit setting is applied to consumer configuration. But, it is hard to say whether this is client or server issue. I uploaded the sample here as maven project: https://github.com/rbaethe/nats-poc.git - does this help?
@rbaethe I figured out the problem. The java documentation is wrong. Rate limit isn't messages per second it's bits per second
The documentation is fixed: https://github.com/nats-io/nats.java/pull/629
Hi @scottf - I think it is not only a documentation issue. In the example implementation, a rate limit 5 is configured (5 Bits per second. So, I would assume if we send 10 messages and each message has a payload size (excl. header) of 176 Bit - first message is consumed immediately after the 9 other messages after a certain amount of time (not sure how this works exactly if the rate limit is < message size). However as you can see in the logs, the first message is received, but even two minutes later, the message was not received by the handler.
2022-03-30 10:07:32.214 INFO 5936 --- [ main] c.s.m.b.p.n.j.c.c.SampleController : consumerPush - RateLimited
{"durable_name":"EXPORTER_RATE_LIMITED","deliver_policy":"all","opt_start_seq":0,"ack_policy":"explicit","ack_wait":10000000000,"max_deliver":3,"max_ack_pending":0,"replay_policy":"instant","sample_freq":"100","rate_limit_bps":5,"flow_control":false,"max_waiting":0}
2022-03-30 10:07:32.269 INFO 5936 --- [ nats:4] c.s.m.b.p.n.j.c.c.SampleController :
Message Received ( 2022-03-30 10:07:32.265:
Headers:
Nats-Expected-Stream: ORDERS
Nats-Msg-Id: ab659f52-a290-4fe0-9eab-b81252a73a1d
Subject: ORDERS.EXPORTER
NatsJetStreamMetaData{prefix='$JS'domain='null', stream='ORDERS', consumer='EXPORTER_RATE_LIMITED', delivered=1, streamSeq=1, consumerSeq=1, timestamp=2022-03-30T10:07:32.166276400+02:00[Europe/Berlin], pending=9}
Message size: 22 bytes, 176 Bit
2022-03-30 10:07:32.479 INFO 5936 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2022-03-30 10:07:32.569 INFO 5936 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 7080 (http) with context path ''
2022-03-30 10:07:32.579 INFO 5936 --- [ main] b.p.n.j.c.SampleClientServiceApplication : Started SampleClientServiceApplication in 2.064 seconds (JVM running for 2.51)
2022-03-30 10:09:10.717 INFO 5936 --- [nio-7080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-30 10:09:10.718 INFO 5936 --- [nio-7080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2022-03-30 10:09:10.718 INFO 5936 --- [nio-7080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 0 ms
2022-03-30 10:09:10.744 INFO 5936 --- [nio-7080-exec-2] c.s.m.b.p.n.j.c.c.SampleController : Log: Test
If this is an issue, it's likely a server issue. We are going to need a much simpler repeatable console example. Is it possible that you are missing the message (not being logged, not being processed)
I did some further tests. It works as expected if the payload is approximately 4000 Bits and the rate limit is configured with 4000 Bits / s. The messages get delivered each second - one by one. With smaller payloads and rate limits, it is behaving as described above.
Defect
rate limit setting not working as expected.
Versions of
io.nats:jnats
andnats-server
:io.nats:jnats: 2.11.6 nats-server : nats:2.7.4-alpine
OS/Container environment:
kubernetes with image: nats:2.7.4-alpine
Steps or code to reproduce the issue:
Expected result:
Actual result: