简体   繁体   English

通过套接字将数据从C ++程序移植到Java程序的输入是否比通过服务器上的原始json或xml文件更快?

[英]Is it faster to port data from a C++ program to a Java program's input via sockets than via a raw json or xml file on the server?

What's the best way to go about things in terms of speed/performance? 就速度/性能而言,最好的处理方式是什么?

Where do things like "Apache Thrift" come in and what are the benefits? 诸如“ Apache Thrift”之类的东西从哪里来?有什么好处?

Please add some good resources I can use to learn about any recommendations! 请添加一些很好的资源,我可以用来了解任何建议!

Thanks all 谢谢大家

Presuming you mean both processes are already running, then it's going to be via sockets. 假设您的意思是两个进程已经在运行,那么它将通过套接字进行。

Writing a file to the disk from one process then reading it from the other is going to incur the performance hit of the disk write and read (and of course whatever method you employ to keep the reader from accessing the file until it's done being written; either locks or an atomic rename on the disk). 从一个进程将文件写入磁盘,然后从另一个进程读取文件,将会导致磁盘读写性能的下降(当然,无论采用哪种方法,都可以阻止读者在文件写入完成之前访问文件; (在磁盘上锁定或原子重命名)。

Even ignoring that, your localhost interface is going to have a faster transfer rate than your disk controller, with the possible exception of a 10Gb fiber channel RAID array with 15k RPM drives in it. 即使忽略这一点,您的本地主机接口的传输速率也将比磁盘控制器更快,但其中可能有一个例外,其中包含15k RPM驱动器的10Gb光纤通道RAID阵列。

Try it out. 试试看。 There's just no other way to find out. 找不到其他方法。

Using sockets or the file system should be comparably fast, since both methods rely on some system calls that are very similar. 使用套接字或文件系统应该相对较快,因为这两种方法都依赖于一些非常相似的系统调用。

Always be aware that this communication involves these steps: 请始终注意,此通信涉及以下步骤:

  1. Encoding your data to a stream of bytes (JSON, XML, YAML, X.509 DER, Java Serialization) 将数据编码为字节流(JSON,XML,YAML,X.509 DER,Java序列化)
  2. Transferring this stream of bytes (TCP socket, UNIX socket, filesystem, ramdisk, pipes) 传输此字节流(TCP套接字,UNIX套接字,文件系统,ramdisk,管道)
  3. Decoding the stream of bytes into data (same as step 1) 将字节流解码为数据(与步骤1相同)

Step 1 and 2 are completely independent, so take that into account when you benchmark. 步骤1和步骤2是完全独立的,因此在进行基准测试时要考虑到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM