为什么 Californium 在使用 CoAP 协议发送数据时等待 65535 条记录
Why Californium wait after 65535 records while sending data using CoAP protocol
我正在使用 Californium API ( https://github.com/eclipse/californium ) 通过 CoAP 协议发送数据。
下面是客户端和服务器的代码片段。
服务器:
public class HelloWorldServer extends CoapServer {
/*
* Application entry point.
*/
public static void main(String[] args) {
try {
// create server
HelloWorldServer server = new HelloWorldServer();
server.start();
} catch (SocketException e) {
System.err
.println("Failed to initialize server: " + e.getMessage());
}
}
/*
* Constructor for a new Hello-World server. Here, the resources of the
* server are initialized.
*/
public HelloWorldServer() throws SocketException {
// provide an instance of a Hello-World resource
add(new HelloWorldResource());
}
/*
* Definition of the Hello-World Resource
*/
class HelloWorldResource extends CoapResource {
public HelloWorldResource() {
// set resource identifier
super("helloWorld");
// set display name
getAttributes().setTitle("Hello-World Resource");
}
@Override
public void handleGET(CoapExchange exchange) {
// respond to the request
exchange.respond("Hello World!");
}
@Override
public void handlePOST(CoapExchange exchange){
//System.out.println("Start "+System.currentTimeMillis());
exchange.accept();
//List<String> queries = exchange.getRequestOptions().getURIQueries();
// System.out.println("Text Received : "+ exchange.getRequestText().length());
// System.out.println("End "+System.currentTimeMillis());
exchange.respond("Received");
}
}
}
客户代码:
try {
long startTime = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
CoapClient client = new CoapClient(new URI("coap://192.168.15.170:5683/helloWorld"));
CoapResponse response = client.post(str, 0);
}
System.out.println("done");
} catch (URISyntaxException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
我正在发送 1000000 条记录,但在第一次发送时它发送了 65535 条记录,它等待了几秒钟 seconds.after 等待几秒钟然后它再次开始发送。
系统详细信息:
OS:Win 7 64 位。
内存:4 GM
为什么在 65535 条记录后等待?
我经历了 Californium.CoAP 每秒接收 250 条记录。我添加了 4 ms.so 的中继,它设法发送少于 250 records/second.
如果您将数据从不同的机器发送到同一个 CoAP 服务器资源,您需要相应地管理延迟。
CoAP 消息 ID (MID) 范围仅限 1-65565。
同时配置 Californium.properties 正常工作。
在我的案例中,每分钟从单个客户端接收超过 60k 条消息,减少 californium.properties(或 NetworkConfig,如果您愿意)中的 EXCHANGE_LIFETIME 是有效的。
顺便提一下:
16位CoAP
消息ID和默认交换生命周期约247秒,
结果是 250 msg/s。因此这是 CoAP RFC7252
的默认限制。
将 EXCHANGE_LIFETIME
更改为较低的值可能会导致其他副作用。
实际上,如果在 EXCHANGE_LIFETIME
之后(意外地)重新接收到消息,则违反了重复数据删除 and/or CON 消息传输。
CoAP
并不是真的要从一个 power client
流式传输数据。因此,我们专注于 Californium 开发以支持用例,其中许多客户端以适中的速率发送消息,从而导致该用例的高吞吐量。
我正在使用 Californium API ( https://github.com/eclipse/californium ) 通过 CoAP 协议发送数据。
下面是客户端和服务器的代码片段。
服务器:
public class HelloWorldServer extends CoapServer {
/*
* Application entry point.
*/
public static void main(String[] args) {
try {
// create server
HelloWorldServer server = new HelloWorldServer();
server.start();
} catch (SocketException e) {
System.err
.println("Failed to initialize server: " + e.getMessage());
}
}
/*
* Constructor for a new Hello-World server. Here, the resources of the
* server are initialized.
*/
public HelloWorldServer() throws SocketException {
// provide an instance of a Hello-World resource
add(new HelloWorldResource());
}
/*
* Definition of the Hello-World Resource
*/
class HelloWorldResource extends CoapResource {
public HelloWorldResource() {
// set resource identifier
super("helloWorld");
// set display name
getAttributes().setTitle("Hello-World Resource");
}
@Override
public void handleGET(CoapExchange exchange) {
// respond to the request
exchange.respond("Hello World!");
}
@Override
public void handlePOST(CoapExchange exchange){
//System.out.println("Start "+System.currentTimeMillis());
exchange.accept();
//List<String> queries = exchange.getRequestOptions().getURIQueries();
// System.out.println("Text Received : "+ exchange.getRequestText().length());
// System.out.println("End "+System.currentTimeMillis());
exchange.respond("Received");
}
}
}
客户代码:
try {
long startTime = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
CoapClient client = new CoapClient(new URI("coap://192.168.15.170:5683/helloWorld"));
CoapResponse response = client.post(str, 0);
}
System.out.println("done");
} catch (URISyntaxException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
我正在发送 1000000 条记录,但在第一次发送时它发送了 65535 条记录,它等待了几秒钟 seconds.after 等待几秒钟然后它再次开始发送。
系统详细信息:
OS:Win 7 64 位。 内存:4 GM
为什么在 65535 条记录后等待?
我经历了 Californium.CoAP 每秒接收 250 条记录。我添加了 4 ms.so 的中继,它设法发送少于 250 records/second.
如果您将数据从不同的机器发送到同一个 CoAP 服务器资源,您需要相应地管理延迟。
CoAP 消息 ID (MID) 范围仅限 1-65565。
同时配置 Californium.properties 正常工作。
在我的案例中,每分钟从单个客户端接收超过 60k 条消息,减少 californium.properties(或 NetworkConfig,如果您愿意)中的 EXCHANGE_LIFETIME 是有效的。
顺便提一下:
16位CoAP
消息ID和默认交换生命周期约247秒,
结果是 250 msg/s。因此这是 CoAP RFC7252
的默认限制。
将 EXCHANGE_LIFETIME
更改为较低的值可能会导致其他副作用。
实际上,如果在 EXCHANGE_LIFETIME
之后(意外地)重新接收到消息,则违反了重复数据删除 and/or CON 消息传输。
CoAP
并不是真的要从一个 power client
流式传输数据。因此,我们专注于 Californium 开发以支持用例,其中许多客户端以适中的速率发送消息,从而导致该用例的高吞吐量。