SSD Parallel I / O and Hard Drives

I have a very strange situation with some of my tests regarding Paralell I / O. Here is the situation. I have several streams that open a file handler in the same file and read from a few places in the file (evenly spaced intervals) a finite number of bytes and upload them to an array. Everything is done using streaming streams. Now I assume that the hard drive should be slower due to random access search. This is why my tests actually target SSDs. It turns out that I hardly get any acceleration when reading the same file from a solid-state drive compared to a hard drive. I wonder what the problem is? This seems to be very surprising to me / I also post my code below to see what I'm doing exactly:

void readFunctor(std::string pathToFile, size_t filePos, BYTE* buffer, size_t buffPos, size_t dataLn, boost::barrier& barier) { FILE* pFile; pFile = fopen(pathToFile.c_str(), "rb"); fseek(pFile, filePos, SEEK_SET); fread(buffer, sizeof(BYTE), dataLn, pFile); fclose(pFile); barier.wait(); } void joinAllThreads(std::vector<boost::shared_ptr<boost::thread> > &threads) { for (std::vector<boost::shared_ptr<boost::thread> >::iterator it = threads.begin(); it != threads.end(); ++it) { (*it).get()->join(); } } void readDataInParallel(BYTE* buffer, std::string pathToFile, size_t lenOfData, size_t numThreads) { std::vector<boost::shared_ptr<boost::thread> > threads; boost::barrier barier(numThreads); size_t dataPerThread = lenOfData / numThreads; for (int var = 0; var < numThreads; ++var) { size_t filePos = var * dataPerThread; size_t bufferPos = var * dataPerThread; size_t dataLenForCurrentThread = dataPerThread; if (var == numThreads - 1) { dataLenForCurrentThread = dataLenForCurrentThread + (lenOfData % numThreads); } boost::shared_ptr<boost::thread> thread( new boost::thread(readFunctor, pathToFile, filePos, buffer, bufferPos, dataLenForCurrentThread, boost::ref(barier))); threads.push_back(thread); } joinAllThreads(threads); } 

Now .. in my main file, I pretty much have ..:

  int start_s = clock(); size_t sizeOfData = 2032221073; boost::shared_ptr<BYTE> buffer((BYTE*) malloc(sizeOfData)); readDataInParallel(buffer.get(), "/home/zahari/Desktop/kernels_big.dat", sizeOfData, 4); clock_t stop_s = clock(); printf("%f %f\n", ((double) start_s / (CLOCKS_PER_SEC)) * 1000, (stop_s / double(CLOCKS_PER_SEC)) * 1000); 

Surprisingly, when reading from an SSD, I do not get acceleration compared to the HDD? Why could this be so?

+4
source share
4 answers

Your file will probably be cached, so that you are measuring processor overhead, not I / O. Instead of clearing the entire disk cache, you can call posix_fadvise() on the file before reading it using the "wontneed" flag to tell the kernel not to cache it. That is, assuming you are on some kind of * nix or Mac OS platform.

+4
source

In your measurements, all the possibilities of creating four streams prevail, each of which does one reading, and then ends when the last of the four streams does barier.wait() .

To measure performance, each thread must make thousands of single-byte reads in a loop before completion.

Here are my suggestions for change:

  void readFunctor(std::string pathToFile, size_t filePos, BYTE* buffer, size_t buffPos, size_t dataLn) { FILE* pFile; pFile = fopen(pathToFile.c_str(), "rb"); fseek(pFile, filePos, SEEK_SET); // initialize random number generation std::random_device rd; tr1::uniform_int_distribution<> randomizer(0, dataLn-1); for (int i=0; i<dataLn; i++) { fseek(pFile, filePos+randomizer(rd), SEEK_SET); fread(buffer++, sizeof(BYTE), 1, pFile); } fclose(pFile); } 
+2
source

Depending on your data size, on an SSD or HDD, the OS will cache your file. So, perhaps you really are not accessing your disks, but your memory.

+2
source

A possible explanation for this is that you are not working under the SATA III configuration. The SATA III 6 Gb / s SSD drive that you are using is connected to the earlier SATA II 3 Gb / s controller on the motherboard. In this case, your SSD is disabled up to 3 Gb / s.

Check your hardware configuration. If it is SATA II, you need to replace mobo so that your SSD reaches its full performance potential.

Check the hard drive on the hard drive to make sure it is SATA, SATA II or SATA III.

Make sure you compare apples to apples at the hardware interface level.

+1
source

Source: https://habr.com/ru/post/1491646/


All Articles