C++;Windows应用程序网络IO吞吐量 我试图编写一个Visual C++ 2008应用程序,运行在Wi2012上,能够在单个Gbps接口(和Gbps交换机)上异步地从NAS上读取/写入文件到2个不同磁盘组。
同时手动复制文件(从网络存储到本地硬盘,从本地硬盘到网络存储)表明,通过我们的系统、网络接口、交换机和NAS,我们能够实现1Gbps的吞吐量(发送950 Mbps,接收950 Mbps)C++;Windows应用程序网络IO吞吐量 我试图编写一个Visual C++ 2008应用程序,运行在Wi2012上,能够在单个Gbps接口(和Gbps交换机)上异步地从NAS上读取/写入文件到2个不同磁盘组。,c++,windows,networking,bandwidth,throughput,C++,Windows,Networking,Bandwidth,Throughput,同时手动复制文件(从网络存储到本地硬盘,从本地硬盘到网络存储)表明,通过我们的系统、网络接口、交换机和NAS,我们能够实现1Gbps的吞吐量(发送950 Mbps,接收950 Mbps) 但是使用我的Visual C++应用程序,它有两个线程(Boost),一个用于读取操作,另一个用于写操作(在单独的文件上),我们有350MbP用于写入,650MbpS用于读取。 停止读写器时,发送或接收速度将提高到950 Mbps 我使用stdiofread/fwrite来读写2MB的数据块 我正在测试很多东西
但是使用我的Visual C++应用程序,它有两个线程(Boost),一个用于读取操作,另一个用于写操作(在单独的文件上),我们有350MbP用于写入,650MbpS用于读取。 停止读写器时,发送或接收速度将提高到950 Mbps
我使用stdiofread/fwrite来读写2MB的数据块 我正在测试很多东西来解决这个问题,我可以稍后解释,但目前,也许有一些明显的东西可以解释为什么我无法获得所需的吞吐量 下面是我复制行为的代码,线程之间没有交互,因此IO操作不应该互相阻塞。我正在与任务管理器检查吞吐量#include <stdio.h>
#include <windows.h>
#include <boost/thread.hpp>
#define INPUT_CHUNK_SIZE 2700000
#define OUTPUT_CHUNK_SIZE 2700000
#define OUTPUT_FILE_DESIRED_SIZE 1000000000
boost::thread* readerProcessThread = NULL;
boost::thread* writerProcessThread = NULL;
bool readerEnded = false;
bool writerEnded = false;
bool stop = false;
const char* inputFileName = "\\\\NASIP\\input\\inputfile.bin";
const char* outputFileName = "\\\\NASIP\\output\\outputfile.bin";
void readerThread()
{
FILE *myFile = fopen(inputFileName, "rb");
char *inputBuffer = new char[INPUT_CHUNK_SIZE];
if(myFile)
{
while(!stop && !feof(myFile))
{
size_t readBytes = fread(inputBuffer, 1, INPUT_CHUNK_SIZE, myFile);
}
fclose(myFile);
}
delete[] inputBuffer;
readerEnded = true;
stop = (writerEnded || !writerProcessThread);
}
void writerThread()
{
char *outputBuffer = new char[OUTPUT_CHUNK_SIZE];
memset(outputBuffer, 0, OUTPUT_CHUNK_SIZE);
FILE *myFile = fopen(outputFileName, "wb");
unsigned long long writtenBytesTotal = 0;
size_t writtenBytes = OUTPUT_CHUNK_SIZE;
if(myFile)
{
while(!stop && writtenBytesTotal < OUTPUT_FILE_DESIRED_SIZE && writtenBytes == OUTPUT_CHUNK_SIZE)
{
size_t writtenBytes = fwrite(outputBuffer, 1, OUTPUT_CHUNK_SIZE, myFile);
writtenBytesTotal += (unsigned long long)writtenBytes;
}
fclose(myFile);
}
writerEnded = true;
stop = (readerEnded || !readerProcessThread);
}
int main(int argc, char * argv[])
{
readerProcessThread = new boost::thread(&readerThread);
writerProcessThread = new boost::thread(&writerThread);
if(readerProcessThread && writerProcessThread)
{
while(!stop)
{
Sleep(1000);
}
}
stop = true;
if (readerProcessThread)
{
readerProcessThread->join();
delete readerProcessThread;
readerProcessThread = NULL;
}
if (writerProcessThread)
{
writerProcessThread->join();
delete writerProcessThread;
writerProcessThread = NULL;
}
return 0;
}
#包括
#包括
#包括
#定义输入块大小2700000
#定义输出块大小2700000
#定义输出文件所需大小100000000
boost::thread*readerProcessThread=NULL;
boost::thread*writerProcessThread=NULL;
bool readerEnded=false;
bool writerEnded=false;
bool-stop=false;
const char*inputFileName=“\\\\NASIP\\input\\inputfile.bin”;
const char*outputFileName=“\\\\NASIP\\output\\outputfile.bin”;
void readerThread()
{
FILE*myFile=fopen(输入文件名,“rb”);
char*inputBuffer=新字符[输入块大小];
如果(我的文件)
{
而(!stop&&!feof(myFile))
{
size\u t readBytes=fread(inputBuffer,1,INPUT\u CHUNK\u size,myFile);
}
fclose(myFile);
}
删除[]输入缓冲区;
readerEnded=true;
停止=(writerEnded | |!writerProcessThread);
}
void writerThread()
{
char*outputBuffer=新字符[输出块大小];
memset(outputBuffer,0,输出块大小);
FILE*myFile=fopen(输出文件名,“wb”);
无符号long-long-writenbytestotal=0;
size\u t writenbytes=输出块大小;
如果(我的文件)
{
而(!stop&&writenbytestotal
-如果您不需要流式读写,请使用copyfile功能。否则,这是一种读者/作者范式。你在锁定缓冲区吗?一个选项是“写入”nolock。显然,增加bufer大小将减少函数调用的开销。您使用的是重叠IO吗?如果您有两个单独的进程,一个读取和一个写入,会发生什么情况?我尝试在单独的进程中执行reader和writer,将线程和进程优先级设置为时间关键型,我得到了相同的结果:reader process或writer process only->950Mbps。读卡器进程和写卡器进程同时运行->650Mbps/350 Mbps如果不需要流式读写,请使用copyfile功能。否则,这是一种读者/作者范式。你在锁定缓冲区吗?一个选项是“写入”nolock。显然,增加bufer大小将减少函数调用的开销。您使用的是重叠IO吗?如果您有两个单独的进程,一个读取和一个写入,会发生什么情况?我尝试在单独的进程中执行reader和writer,将线程和进程优先级设置为时间关键型,我得到了相同的结果:reader process或writer process only->950Mbps。读卡器进程和写卡器进程同时运行->650Mbps/350 Mbps