增加时间戳UDP包

时间:2017-01-22 15:37:12

标签: c++ boost udp asio

我想检索使用boost asio接收的UDP数据包的接收时间戳。

我发现内核提供了套接字选项SO_TIMESTAMP,它应该允许在NIC接收数据包时生成时间戳。 我还发现这个旧的ticket提出了一个补丁来增加对SO_TIMESTAMP的支持。

我使用boost 1.60.0而我无法启用此选项:

ip::udp::socket sock; 
... 
sock.set_option(ip::unicast::timestamp(true));

如何通过boost检索UDP数据包接收时间并计算自收到同步或异步读取数据包后接收的经过时间?

1 个答案:

答案 0 :(得分:1)

似乎boost尚未实现此选项,如果您的平台支持辅助数据,您可以使用本机套接字执行此操作:

17/01/25 14:40:19 INFO Client: Requesting a new application from cluster with 2 NodeManagers
17/01/25 14:40:19 INFO Client: Verifying our application has not requested more than the maximum memory capability of the cluster (11520 MB per container)
Exception in thread "main" java.lang.IllegalArgumentException: Required executor memory (20480+2048 MB) is above the max threshold (11520 MB) of this cluster! Please check the values of 'yarn.scheduler.maximum-allocation-mb' and/or 'yarn.nodemanager.resource.memory-mb'.
    at org.apache.spark.deploy.yarn.Client.verifyClusterResources(Client.scala:304)
    at org.apache.spark.deploy.yarn.Client.submitApplication(Client.scala:164)
    at org.apache.spark.deploy.yarn.Client.run(Client.scala:1119)
    at org.apache.spark.deploy.yarn.Client$.main(Client.scala:1178)
    at org.apache.spark.deploy.yarn.Client.main(Client.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:736)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:185)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:210)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:124)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Command exiting with ret '1'

然后从本机套接字访问控制消息:

int socket = sock.native(); 
int opt = 1;
setsockopt( sock, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt));