What is concurrency and how can it be implemented?
Concurrency is basically multiple computations or doing more than one thing at a time. Concurrency is everywhere in programming. Web servers would definitely need to implement concurrency because they support many requests simultaneously.
There are various ways to implement concurrency. such as multiprocessing and multithreading or an approach that uses both standard implementation methods.
How is concurrency implemented with Node.js?
Node.js has another approach to concurrency. It uses the I/O operations model that uses asynchronous non-blocking I/O calls to implement concurrency.
JavaScript is a single-threaded asynchronous (but not parallel) programming language yet everything done on the web tends to be blocking or time-consuming.
Javascript code runs fundamentally in a single threaded event loop environment. So this means in any given instance only one of the functions or lines of JS code can be running. Although this looks like a tremendous limitation in fact it’s a huge freedom, it’s a freedom from having to manage all the possible complexities that may have caused otherwise in parallel programming. Concurrency doesn’t mean at any given moment something is happening but more about two higher level sets of tasks are occurring within the same time frame.
The event loop is related to concurrency because it is responsible for exucuting the code, collecting and processing events, and executing queud sub-tasks.
Web API's relate to implementing concurrency when the Web API's are called from remote servers. Most of the time we have to make two or more calls depending on the requests.
Concurrency compared in Oracle and MongoDB
MongoDB uses multi-granularity locking [1] that allows operations to lock at the global, database or collection level, and allows for individual storage engines to implement their own concurrency control below the collection level (e.g., at the document-level in WiredTiger).
MongoDB uses reader-writer locks that allow concurrent readers shared access to a resource, such as a database or collection.
with Oracle in general, multiuser databases use some form of data locking to solve the problems associated with data concurrency, consistency, and integrity. Locks are mechanisms that prevent destructive interaction between transactions accessing the same resource.
Oracle automatically provides read consistency to a query so that all the data that the query sees comes from a single point in time (statement-level read consistency). Oracle can also provide read consistency to all of the queries in a transaction (transaction-level read consistency).
Oracle uses the information maintained in its rollback segments to provide these consistent views. The rollback segments contain the old values of data that have been changed by uncommitted or recently committed transactions.
To read more about concurrency follow the links below:
https://docs.oracle.com/cd/B19306_01/server.102/b14220/consist.htm
https://www.mongodb.com/docs/manual/faq/concurrency/

No comments:
Post a Comment