public void TestBlocksPerSecond()
        {
            //UnmanagedMemory.Memory.UseLargePages = true;
            DebugStopwatch sw = new DebugStopwatch();

            using (MemoryPoolStream ms = new MemoryPoolStream())
            {
                using (BinaryStreamIoSessionBase io = ms.CreateIoSession())
                {
                    BlockArguments args = new BlockArguments();
                    args.Position  = ms.BlockSize * 2000L - 1;
                    args.IsWriting = true;

                    io.GetBlock(args);

                    double sec = sw.TimeEvent(() =>
                    {
                        for (int y = 0; y < 100; y++)
                        {
                            for (int x = 0; x < 2000; x++)
                            {
                                args.Position = (long)x * ms.BlockSize;
                                io.GetBlock(args);
                            }
                        }
                    });

                    System.Console.WriteLine("Get Blocks: " + (200000 / sec / 1000000).ToString("0.00 Million Per Second"));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new DiskIoSession that can be used to read from the disk subsystem.
        /// </summary>
        /// <param name="diskIo">owner of the disk</param>
        /// <param name="ioSession">the base ioSession to use for this io session</param>
        /// <param name="file">The file that will be read from this diskIoSession</param>
        public DiskIoSession(DiskIo diskIo, BinaryStreamIoSessionBase ioSession, FileHeaderBlock header, SubFileHeader file)
        {
            if (diskIo == null)
            {
                throw new ArgumentNullException("diskIo");
            }
            if (diskIo.IsDisposed)
            {
                throw new ObjectDisposedException(diskIo.GetType().FullName);
            }
            if (ioSession == null)
            {
                throw new ArgumentNullException("ioSession");
            }
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            m_args = new BlockArguments();
            m_lastReadonlyBlock      = diskIo.LastReadonlyBlock;
            m_diskMediumIoSession    = ioSession;
            m_snapshotSequenceNumber = header.SnapshotSequenceNumber;
            m_fileIdNumber           = file.FileIdNumber;
            m_isReadOnly             = file.IsReadOnly || diskIo.IsReadOnly;
            m_blockSize = diskIo.BlockSize;
            m_diskIo    = diskIo;
            IsValid     = false;
            IsDisposed  = false;
        }
        public void TestBlocksPerSecond()
        {
            //UnmanagedMemory.Memory.UseLargePages = true;
            DebugStopwatch sw = new DebugStopwatch();
            using (MemoryPoolStream ms = new MemoryPoolStream())
            {
                using (var io = ms.CreateIoSession())
                {
                    BlockArguments args = new BlockArguments();
                    args.Position = ms.BlockSize * 2000L - 1;
                    args.IsWriting = true;

                    io.GetBlock(args);

                    double sec = sw.TimeEvent(() =>
                        {
                            for (int y = 0; y < 100; y++)
                                for (int x = 0; x < 2000; x++)
                                {
                                    args.Position = (long)x * ms.BlockSize;
                                    io.GetBlock(args);
                                }
                        });

                    System.Console.WriteLine("Get Blocks: " + (200000 / sec / 1000000).ToString("0.00 Million Per Second"));
                }
            }


        }
Esempio n. 4
0
 /// <summary>
 /// Gets a block for the following Io session.
 /// </summary>
 /// <param name="args">the <see cref="BlockArguments"/> to use to read and write to a block</param>
 public override void GetBlock(BlockArguments args)
 {
     if (IsDisposed)
     {
         throw new ObjectDisposedException(GetType().FullName);
     }
     m_stream.GetBlock(this, args);
 }
Esempio n. 5
0
 public override void GetBlock(BlockArguments args)
 {
     if (args.IsWriting && m_file.m_isReadOnly)
     {
         throw new ReadOnlyException("File system is read only");
     }
     args.SupportsWriting = !m_file.m_isReadOnly;
     m_file.GetBlock(args);
 }
            public override void GetBlock(BlockArguments args)
            {
                int  blockDataLength = m_blockDataLength;
                long pos             = args.Position;

                if (IsDisposed || m_dataIoSession.IsDisposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }
                if (pos < 0)
                {
                    throw new ArgumentOutOfRangeException("position", "cannot be negative");
                }
                if (pos >= (long)blockDataLength * (uint.MaxValue - 1))
                {
                    throw new ArgumentOutOfRangeException("position", "position reaches past the end of the file.");
                }

                uint physicalBlockIndex;
                uint indexPosition;

                if (pos <= uint.MaxValue) //64-bit divide is 2 times slower
                {
                    indexPosition = ((uint)pos / (uint)blockDataLength);
                }
                else
                {
                    indexPosition = (uint)((ulong)pos / (ulong)blockDataLength); //64-bit signed divide is twice as slow as 64-bit unsigned.
                }
                args.FirstPosition = (long)indexPosition * blockDataLength;
                args.Length        = blockDataLength;

                if (args.IsWriting)
                {
                    throw new Exception("File is read only");
                }
                else
                {
                    //Reading
                    if (indexPosition >= m_stream.m_subFile.DataBlockCount)
                    {
                        throw new ArgumentOutOfRangeException("position", "position reaches past the end of the file.");
                    }
                    physicalBlockIndex = m_stream.m_subFile.DirectBlock + indexPosition;

                    m_dataIoSession.Read(physicalBlockIndex, BlockType.DataBlock, indexPosition);
                    args.FirstPointer    = (IntPtr)m_dataIoSession.Pointer;
                    args.SupportsWriting = false;
                }
            }
 public void TestAlignment()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.ConfigureAlignment(41211, 4096);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
         args.Position = 41211;
         ms.GetBlock(args);
         Assert.AreEqual(41211L, args.FirstPosition);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes - (41211 % 4096), args.Length);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
 public void TestAllocateAndDeallocate()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         args.Position = Globals.MemoryPool.PageSize;
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 2 * Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
Esempio n. 9
0
 public void TestAlignment()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.ConfigureAlignment(41211, 4096);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
         args.Position = 41211;
         ms.GetBlock(args);
         Assert.AreEqual(41211L, args.FirstPosition);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes - (41211 % 4096), args.Length);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
Esempio n. 10
0
 public void TestAllocateAndDeallocate()
 {
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
     using (MemoryPoolStreamCore ms = new MemoryPoolStreamCore())
     {
         BlockArguments args = new BlockArguments();
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, Globals.MemoryPool.PageSize);
         args.Position = Globals.MemoryPool.PageSize;
         ms.GetBlock(args);
         Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 2 * Globals.MemoryPool.PageSize);
     }
     Assert.AreEqual(Globals.MemoryPool.AllocatedBytes, 0L);
 }
Esempio n. 11
0
        public override void GetBlock(BlockArguments args)
        {
            if (args is null)
            {
                throw new ArgumentNullException("args");
            }

            long pos = args.Position;

            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (pos < 0)
            {
                throw new ArgumentOutOfRangeException("position", "cannot be negative");
            }
            if (pos >= m_blockDataLength * (uint.MaxValue - 1))
            {
                throw new ArgumentOutOfRangeException("position", "position reaches past the end of the file.");
            }

            uint physicalBlockIndex;
            uint indexPosition;

            if (pos <= uint.MaxValue) //64-bit divide is 2 times slower
            {
                indexPosition = (uint)pos / (uint)m_blockDataLength;
            }
            else
            {
                indexPosition = (uint)((ulong)pos / (ulong)m_blockDataLength); //64-bit signed divide is twice as slow as 64-bit unsigned.
            }
            args.FirstPosition = indexPosition * m_blockDataLength;
            args.Length        = m_blockDataLength;

            physicalBlockIndex = m_subFile.DirectBlock + indexPosition;

            Read(physicalBlockIndex, indexPosition);

            args.FirstPointer    = m_memory.Address;
            args.SupportsWriting = true;
        }
        public void Test1()
        {
            MemoryPoolTest.TestMemoryLeak();
            MemoryPoolFile file = new MemoryPoolFile(Globals.MemoryPool);

            BinaryStreamIoSessionBase session = file.CreateIoSession();

            BlockArguments blockArguments = new BlockArguments();

            blockArguments.IsWriting = true;
            blockArguments.Position  = 10000000;
            session.GetBlock(blockArguments);


            System.Console.WriteLine("Get Block\t" + StepTimer.Time(10, () =>
            {
                blockArguments.Position = 100000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 200000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 300000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 400000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 500000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 600000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 700000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 800000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 900000;
                session.GetBlock(blockArguments);
                blockArguments.Position = 1000000;
                session.GetBlock(blockArguments);
            }));
            file.Dispose();
            MemoryPoolTest.TestMemoryLeak();
        }
Esempio n. 13
0
        /// <summary>
        /// Populates the pointer data inside <see cref="args"/> for the desired block as specified in <see cref="args"/>.
        /// This function will block if needing to retrieve data from the disk.
        /// </summary>
        /// <param name="pageLock">The reusable lock information about what this block is currently using.</param>
        /// <param name="args">Contains what block needs to be read and when this function returns,
        /// it will contain the proper pointer information for this block.</param>
        private void GetBlock(PageReplacementAlgorithm.PageLock pageLock, BlockArguments args)
        {
            pageLock.Clear();
            //Determines where the block is located.
            if (args.Position >= m_lengthOfCommittedData)
            {
                //If the block is in the uncommitted space, it is stored in the
                //MemoryPoolStreamCore.
                args.SupportsWriting = true;
                m_writeBuffer.GetBlock(args);
            }
            else if (args.Position < m_lengthOfHeader)
            {
                //If the block is in the header, error because this area of the file is not designed to be accessed.
                throw new ArgumentOutOfRangeException("args", "Cannot use this function to modify the file header.");
            }
            else
            {
                //If it is between the file header and uncommitted space,
                //it is in the committed space, which this space by design is never to be modified.
                if (args.IsWriting)
                {
                    throw new ArgumentException("Cannot write to committed data space", "args");
                }
                args.SupportsWriting = false;
                args.Length          = m_diskBlockSize;
                //rounds to the beginning of the block to be looked up.
                args.FirstPosition = args.Position & ~(long)m_pool.PageMask;

                GetBlockFromCommittedSpace(pageLock, args.FirstPosition, out args.FirstPointer);

                //Make sure the block does not go beyond the end of the uncommitted space.
                if (args.FirstPosition + args.Length > m_lengthOfCommittedData)
                {
                    args.Length = (int)(m_lengthOfCommittedData - args.FirstPosition);
                }
            }
        }
            public override void GetBlock(BlockArguments args)
            {
                int  blockDataLength = m_blockDataLength;
                long pos             = args.Position;

                if (IsDisposed || m_ioSessions.IsDisposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }
                if (pos < 0)
                {
                    throw new ArgumentOutOfRangeException("position", "cannot be negative");
                }
                if (pos >= (long)blockDataLength * (uint.MaxValue - 1))
                {
                    throw new ArgumentOutOfRangeException("position", "position reaches past the end of the file.");
                }

                uint physicalBlockIndex;
                uint indexPosition;

                if (pos <= uint.MaxValue) //64-bit divide is 2 times slower
                {
                    indexPosition = ((uint)pos / (uint)blockDataLength);
                }
                else
                {
                    indexPosition = (uint)((ulong)pos / (ulong)blockDataLength); //64-bit signed divide is twice as slow as 64-bit unsigned.
                }
                args.FirstPosition = (long)indexPosition * blockDataLength;
                args.Length        = blockDataLength;

                if (args.IsWriting)
                {
                    //Writing
                    if (m_isReadOnly)
                    {
                        throw new Exception("File is read only");
                    }
                    bool wasShadowPaged;
                    physicalBlockIndex = m_pager.VirtualToShadowPagePhysical(indexPosition, out wasShadowPaged);

                    if (wasShadowPaged)
                    {
                        m_stream.ClearIndexNodeCache(this, m_parser);
                    }

                    if (physicalBlockIndex == 0)
                    {
                        throw new Exception("Failure to shadow copy the page.");
                    }

                    DataIoSession.WriteToExistingBlock(physicalBlockIndex, BlockType.DataBlock, indexPosition);
                    args.FirstPointer    = (IntPtr)DataIoSession.Pointer;
                    args.SupportsWriting = true;
                }
                else
                {
                    //Reading
                    physicalBlockIndex = m_parser.VirtualToPhysical(indexPosition);
                    if (physicalBlockIndex <= 0)
                    {
                        throw new Exception("Page does not exist");
                    }

                    DataIoSession.Read(physicalBlockIndex, BlockType.DataBlock, indexPosition);
                    args.FirstPointer    = (IntPtr)DataIoSession.Pointer;
                    args.SupportsWriting = !m_isReadOnly && physicalBlockIndex > m_lastEditedBlock;
                }
            }
Esempio n. 15
0
 public void get_block([ArgRequired] BlockArguments args)
 {
     OutputJson(ChainAPIProvider.GetInstance(args.host.AbsoluteUri).GetBlock(args.block_num_or_id));
 }