Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MemoryMappedFile with very slow CreateViewStream

I'm using a memory mapped file that is approx. 100 GB of data. When I call CreateViewStream on that file it takes 30 minutes to create it and seems that it's because of the size of the memory mapped file but, why does take it so long? Does it copy the whole file into managed memory?

It takes much longer when I write the file with a file stream and access it without a reboot. (strangely)

like image 336
Sebastian Avatar asked Aug 19 '15 06:08

Sebastian


1 Answers

I'm unable to replicate these issues. Here's the code I used to test:

    static void Main(string[] args)
    {
        var sw = Stopwatch.StartNew();
        var mmf = MemoryMappedFile.CreateFromFile(@"f:\test.bin");
        var stream = mmf.CreateViewStream();
        for (int i = 0; i < 100000; i++)
        {
            stream.ReadByte();
        }
        Console.WriteLine(sw.Elapsed);
    }

f:\test.bin is a 100GB zero filled file that I generated for the purposes of this test. I'm able to create the MemoryMappedFile, then run CreateViewStream and read 100,000 bytes from it in 3.7s.

Please provide sample code that's exhibiting the behavior you've described and I'll be glad to pick it apart and see what's going on.

like image 186
willaien Avatar answered Sep 18 '22 04:09

willaien