Topics in database development and program parallelism
Tags: computerscience, database, datascience, algorithms
Published: 2022-02-05 13:06:06

**Introduction**

Concurrency and parallelism are incredibly important topics in computer science, and are also a hot topic in industry today. Computers are gaining more and more cores, yet many programmers aren’t prepared to fully utilize them [7]. we are going to cover some of the highly cited topics and subjects in the area of parallel programming and concurrency, the topics are not exhaustive, however the main goal or objective is to make them to be.

**Granularity**

The size of data items is often called the data item granularity, to be precise the amount of computation in relation to communication [4] , coarse granularity refers to large item sizes, data is communicated infrequently, after larger amounts of computation, Fine granularity refers to small item sizes, individual tasks are relatively small in terms of code size and execution time. The data is transferred among processors frequently in amounts of one or a few memory words. The coarse granularity of data accesses is one of the reasons why B+tree indexing is not efficient for use in parallel computations, it is known that the larger the data item size is, the lower the degree of concurrency permitted, paraphrasing “the finer the granularity, the greater the potential for parallelism and hence speed-up, but the greater the overheads of synchronization and communication” [4].

Both Fine and Coarse Granularity have their own drawbacks, In order to attain the best parallel performance, the best balance between load and communication overhead needs to be found. If the granularity is too fine, the performance can suffer from the increased communication overhead. On the other side, if the granularity is too coarse, the performance can suffer from load imbalance. [4]


![Coarse grained (a) fine grained (b)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xa48j0h1yd9gwkdpxmgy.png) 

Simple Example, a business address can be recorded, with coarse granularity, 

business address = 200 2nd Ave. South #358, St. Petersburg, FL 33701-4313 USA, 

as a single field a string or as a finer granularity, this is a method most followed by Doctrine ORM when modelling data entities.

    street address = 200 2nd Ave. South #358
    city = St. Petersburg
    state = FL
    postal code = 33701-4313
    country = USA

This principles are used in the design and development of API’s, one use case maybe in the event in which remote calls are likely to be slower than local calls, the parameters in remote methods should be relatively coarse-grained. A coarse-grained object contains more data than a fine-grained one, so fewer access calls are required. For the same reason, the parameters of the methods called by web service clients should also be coarse-grained.[5]

**Locks Vs Latches as a concurrency control technique**

There is an important distinction between locks and latches when discussing how the DBMS protects its internal elements, A lock is a higher-level, logical primitive that protects the contents of a database (e.g., tuples, tables,databases) from other transactions. Transactions will hold a lock for its entire duration. Database systems can expose to the user the locks that are being held as queries are run. Latches are the low-level protection primitives used for critical sections the DBMS’s internal data structures (e.g., data structure, regions of memory) from other threads. Latches are held for only the duration of the operation being made.[6] Latches can be implemented by using OS mutex,

**SMID (Single Instruction Multiple Data)** – a class of parallel computers in Flynn’s Classification. It outlines the computers with multiple processing elements that can perform the same operation on multiple data points simultaneously.It has been extensively used in database research to boost the performance of database operations. The paper in references index [3] shows how the performance of mergesort, a classical sort algorithm, can be improved, when equipped with SIMD, it has been shown that the SIMD-based implementation of many database operators, including scan, aggregation, indexing and join, perform much better than its non-SIMD counterpart.

## Competitiveness of In-memory databases

**DRAM (Dynamic random-access memory)** has orders of magnitude higher bandwidth and lower latency than hard disks, or even flash memory for that matter,With exponentially increasing memory sizes and
falling prices, it is now frequently possible to accommodate
the entire database and its associated indices in memory,thereby completely eliminating the significant overheads of slow disk accesses.

**NUMA Non-uniform memory access (NUMA)** is a computer memory design used in multiprocessing, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory (memory local to another processor or memory shared between processors). The benefits of NUMA are limited to particular workloads, notably on servers where the data is often associated strongly with certain tasks or users [8]. NUMA architecture opens up opportunities for optimization in terms of cache coherence and memory access, which
can significantly hinder the performance if not taken into design . Since accessing the memory affiliated with remote (non-local) NUMA nodes is substantially costlier than accessing local memory, the major direction for NUMA-aware optimization is to reduce the accesses of remote memory, and meanwhile keep load balancing among NUMA nodes.
Many systems have been proposed with NUMA aware optimizations. ERIS is an in-memory storage engine which employs an adaptive partitioning mechanism to realize NUMA topology and hence reduce remote memory accesses.

**Conclusion**

Concurrency and parallelism can speed up a lot of classical algorithms and help produce faster programs as a result we dedicate our effort in covering a lot of topics under this category follow me on twitter for more updates.

**References**

1. https://www.brainkart.com/article/Granularity-of-Data-Items-and-Multiple-Granularity-Locking_11567/

2. https://www.geeksforgeeks.org/difference-between-fine-grained-and-coarse-grained-simd-architecture/

3. J. Chhugani, A. D. Nguyen, V. W. Lee, W. Macy, M. Hagog, Y.-K. Chen, A. Baransi, S. Kumar, and P. Dubey. Efficient Implementation of Sorting on Multi-Core SIMD CPU Architecture. PVLDB,1(2):1313–1324, 2008.

4. https://en.wikipedia.org/wiki/Granularity

5. https://docs.oracle.com/cd/E19798-01/821-1841/gipkv/index.html

6. https://15445.courses.cs.cmu.edu/fall2020/notes/09-indexconcurrency.pdf

7. http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/concurrency.html

8. https://en.wikipedia.org/wiki/Non-uniform_memory_access