Changes between Version 6 and Version 7 of rfc47_dataset_caching


Ignore:
Timestamp:
Jul 29, 2014, 12:32:25 PM (10 years ago)
Author:
flippmoke
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • rfc47_dataset_caching

    v6 v7  
    9393=== Solution 1 (RW Mutex in GDALDataset ) ===
    9494
    95 For solution one the three mutexes are:
     95==== Mutexes ====
     96
     97For solution 1 the three mutexes are:
    9698
    9799 * Dataset RW Mutex (per GDALDataset)
     
    101103In order to prevent deadlocks, a priority of the mutexes is established in the order they are listed. For example if you have the Band Mutex, you may not obtain the Dataset RW Mutex, unless it was obtained prior to the Band Mutex being obtained. However, the goal should always be to never have more then mutex at a time!
    102104
    103 === Dataset RW Mutex ===
     105===== Dataset RW Mutex =====
    104106
    105107The objective of the Dataset RW Mutex is to protect the data stored within the the GDALRasterBlocks associated with a dataset, and lock during large Read or Write operations. This prevents two different threads from using memcpy on the same GDALRasterBlock at the same time. This mutex normally lies within the GDALDataset, but in the case of a standalone GDALRasterBand, it utilizes a new mutex on the Band.
    106108
    107 === Band Mutex ===
     109===== Band Mutex =====
    108110
    109111The objective of the Band Mutex is to manage the control of the array of blocks in the GDALRasterBand, and manages the locking of the GDALRasterBlocks. This is a per GDALRasterBand Mutex.
    110112
    111 === RBM Mutex ===
     113===== RBM Mutex =====
    112114
    113115The objective of the RBM Mutex is to manage control of the LRU cache. This mutex is responsible for the control of the management of the cache's linked list and total amount of data stored in the cache.
    114116
     117==== Pros ====
    115118
     119This is a much more simple solution of the two different possible solutions. Since the protection of the Blocks are done at the Dataset level, it prevents the problem of some drivers such as geotiff where more then one band might be accessed in the reading or writing of one band. Therefore with out this protection here it could cause issues if locking was just at a band level per block's data.
    116120
     121==== Cons ====
    117122
     123This solution is not perhaps the most optimal way to lock because the protection of the IReadBlock, IWriteBlock, and IRasterIO routines is over the entire dataset. This is very limiting when you are reading the same dataset in a threaded environment, because it is not possible to read more then one block at a time.
     124
     125=== Solution 2 (RW Mutex in GDALRasterBlock ) ===
     126
     127==== Mutexes ====
     128
     129For solution 2 the three mutexes are:
     130
     131 * Band Mutex (per GDALRasterBand)
     132   * RBM Mutex (per GDALRasterBlockManager)
     133   * Block RW Mutex (per GDALRasterBlock)
     134
     135In order to prevent deadlocks the band mutex has priority. This means that you can not get the Band Mutex if you have the RBM or Blow RW Mutex, unless you already had the Band Mutex prior to this. You may not obtain the Block mutex and the RBM mutex at the same time.
     136
     137===== Band Mutex =====
     138
     139The objective of the Band Mutex is to manage the control of the array of blocks in the GDALRasterBand, and manages the locking of the GDALRasterBlocks. This is a per GDALRasterBand Mutex.
     140
     141===== RBM Mutex =====
     142
     143The objective of the RBM Mutex is to manage control of the LRU cache. This mutex is responsible for the control of the management of the cache's linked list and total amount of data stored in the cache.
     144
     145===== Block RW Mutex =====
     146
     147The objective of the Block RW Mutex is to protect the data stored within the the GDALRasterBlocks associated with a dataset, and lock during large Read or Write operations. This prevents two different threads from using memcpy on the same GDALRasterBlock at the same time. It is created on a per block basis.
     148
     149==== Pros ====
     150
     151This is probably the most complete solution to making an intensive and fast threaded solution for the blocking. This is because the IReadWrite, IWriteBlock, and IRasterIO now are able to possibly pass a mutex with their calls, as a void pointer pointer. A change was made to the mutex as well such that a void pointer pointer that is NULL passed to CPLMutexHolderD, will not result in any pointer being created or any locking to occur. This means much of the behavior of the existing code can be maintained by simply passing a NULL value for the mutex. All of these changes allow the drivers to maintain much more control over the way that locking occurs when protecting the data inside a block.
     152
     153==== Cons ====
     154
     155Obviously, this is a much more complex solution and therefore is harder to manage. It means that writing a driver is not as trivial as before and care must be taken in how locking is done within the driver in order to prevent deadlocks and maintain thread safety. The other issue that might arise from this is a slight slow down in non-threaded code because of the extra cycles spent locking data that will not be accessed in a threaded manner. Additionally, it might have issues in windows if too many mutexes are created (as there are quite a few more since it is a per GDALRasterBlock mutex). (Note: Not sure how I will be able to test this properly?)