californium - Caused by: java.lang.IllegalStateException: automatic message IDs exhausted

    我们做的物联网项目的底层协议适配接入是用californium开源项目来做的,上层是使用leshan的1.2.0版本来做的,使用的是californium-2.4.1,最新版是2.6.0,按道理说应该是很稳定的版本了,但是依然在我们做并发测试的时候,出现了异常message IDs exhausted, could not register outbound request for tracking

2020-12-29 12:30:16.843 [CoapServer(main)#1] WARN o.e.c.c.n.InMemoryMessageExchangeStore 226 - [LWM2M Server-coap://] cannot send message to /XX.XX.XX.XX:YYYY, all MIDs are in use
2020-12-29 12:30:16.843 [CoapServer(main)#1] WARN o.e.c.core.network.UdpMatcher 136 - message IDs exhausted, could not register outbound request for tracking
org.eclipse.leshan.core.request.exception.SendFailedException: Request CON-GET MID= -1, Token=null, OptionSet={"Uri-Path":["1","0"]}, automatic message IDs exhausted no payload cannot be sent
at org.eclipse.leshan.core.californium.CoapSyncRequestObserver.onSendError(CoapSyncRequestObserver.java:106)
at org.eclipse.californium.core.coap.Message.setSendError(Message.java:1063)
at org.eclipse.californium.core.coap.Request.setSendError(Request.java:1133)
at org.eclipse.californium.core.network.UdpMatcher.sendRequest(UdpMatcher.java:137)
at org.eclipse.californium.core.network.CoapEndpoint$OutboxImpl.sendRequest(CoapEndpoint.java:981)
at org.eclipse.californium.core.network.stack.BaseCoapStack$StackBottomAdapter.sendRequest(BaseCoapStack.java:231)
at org.eclipse.californium.core.network.stack.ReliabilityLayer.sendRequest(ReliabilityLayer.java:107)
at org.eclipse.californium.core.network.stack.BlockwiseLayer.sendRequest(BlockwiseLayer.java:333)
at org.eclipse.californium.core.network.stack.AbstractLayer.sendRequest(AbstractLayer.java:69)
at org.eclipse.californium.core.network.stack.AbstractLayer.sendRequest(AbstractLayer.java:69)
at org.eclipse.californium.core.network.stack.ExchangeCleanupLayer.sendRequest(ExchangeCleanupLayer.java:63)
at org.eclipse.californium.core.network.stack.BaseCoapStack$StackTopAdapter.sendRequest(BaseCoapStack.java:188)
at org.eclipse.californium.core.network.stack.BaseCoapStack.sendRequest(BaseCoapStack.java:87)
at org.eclipse.californium.core.network.CoapEndpoint$8.run(CoapEndpoint.java:829)
at org.eclipse.californium.elements.util.SerialExecutor$1.run(SerialExecutor.java:289)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: automatic message IDs exhausted
... 15 common frames omitted

     试了很多办法后并没有解决这个问题,没办法只能请教californium的开发人员:https://github.com/eclipse/californium/issues/1487

     回复还挺快的,基本上我提问题,第二天就可以收到回复了,赞,大大的赞!!!

     经过@boaks的回答,逐渐找到了问题所在,是有一个参数配置有问题,MAX_ACTIVE_PEERS=10

     然而如果这个参数不设置,代码中是用默认值的,MAX_ACTIVE_PEERS=150000

trackers = new LeastRecentlyUsedCache<>(config.getInt(NetworkConfig.Keys.MAX_ACTIVE_PEERS, 150000),
				config.getLong(NetworkConfig.Keys.MAX_PEER_INACTIVITY_PERIOD, 10 * 60));

    那么我们再看看这个参数的作用;(是设备接入最大的数量,默认的10肯定是不够的,因为我的模拟量就是10个的并发。。。)

/**
		 * The maximum number of active peers supported.
		 * <p>
		 * An active peer is a node with which we exchange CoAP messages. For
		 * each active peer we need to maintain some state, e.g. we need to keep
		 * track of MIDs and tokens in use with the peer. It therefore is
		 * reasonable to limit the number of peers so that memory consumption
		 * can be better predicted.
		 * <p>
		 * The default value of this property is
		 * {@link NetworkConfigDefaults#DEFAULT_MAX_ACTIVE_PEERS}.
		 * <p>
		 * For clients this value can safely be set to a small one or two digit
		 * number as most clients will only communicate with a small set of
		 * peers (servers).
		 */
		public static final String MAX_ACTIVE_PEERS = "MAX_ACTIVE_PEERS";
		/**
		 * The maximum number of seconds a peer may be inactive for before it is
		 * considered stale and all state associated with it can be discarded.
		 */
		public static final String MAX_PEER_INACTIVITY_PERIOD = "MAX_PEER_INACTIVITY_PERIOD";

     我就将这个参数改成更大一点就可以了;下面是我修改Californium.properties的参数,或者直接删掉配置文件的MAX_ACTIVE_PEERS参数,就会使用代码中默认的值 For Your Information

posted @ 2022-01-27 18:35  zhangdaopin  阅读(97)  评论(0编辑  收藏  举报