Friday, April 30, 2010

How to get Scalability?

Every archtecture must improve on some NFRs. Namely, Salability, Reliability, Performance, Security etc.


Q What do you do to make your architecture scalable?
Uniersal law of scalability :
C(N) = N/(1+Contention*((N-1)+Coherency*N*(N-1)))
Contention and Coherehncy are conflicting part of any parallel system. Both should be low for higher scalability.

 
Example, You may remove contention of table locking by zero sharing by fully de-normalized data. That is there is multiple data in each table. Different request can independently update it independent table and there is no locking and hence wait for accessing table - zero contention.

 
But it increase time for coherency, because now data is incositent state. De-normalized table has duplicate data threfore different instance of data at different state. Now time required to bring the data in consitent state is coherency.
Hence, we must make effort to reduce both.

Reduce Contention
where, contention is race/conflict to use the shared system. Example, is there is shared file which is to be read by multiple request. Then request will be competing to read the file. If one file is reading then other will be waiting for reading it because of lock. This waiting time is the measure of contency. If we can reduce this contention the system will get more scalable becuase there will be no waiting for accessing the shared resources.

 
Remove Sharing

  1. Shared Nothing Architecture, each node is independent and self-sufficient, and there is no single point of contention across the system. The desing pattern against the shared centralized system. Instead of using the big fat database use the leaner multiple databases.
  2. Narrow lock scope is for reducing this sharing and hence the bone of contention. This usually effected by partitioning the resources like data such that there each request has access to its own partition and and hence no contention and no waiting. Also called sharding.
  3. Reducing the time of lock - Lock Striping - Lock Partitions instead of entire object, Reduce the scpe of the lock on larger segment into multiple loc of smaller segmentSplitting the lock of the entire system into multiple lock of smaller segments. Example of Concurrent HashMap
  4. Reducing the time of lock - Lock Splitting - Instead of locking entire object ; lock smaller variable which are point of contention.
Remove Latency
Higher the latency higher is the service time of the resources. Example - Database reads are slow hence becuase IO access latency. Hence, few threads are able to use the database read without contention. If the aceessing time of the data can be reduce the number of thread acessing that resource without contention will reduce.
  1. Use of in-memory objects instead of using database. Like recently popular Space Architecture (Google Wave)
  2. Use cache to remove the frequetly access queries from database. Like Memcahce
Reduce Coherency
where, coherency is the time spent for coordination to make data consistent if data was not centralized. Coherency is effort spent to coordiante the distributed database. Includes management for transactions, security, session etc.
Reduce coordination time and centrlize issue needing coordination.

 
  1. Centralized sessions or Stateless - Stateless programs needs no coordination like Autonomic Services
  2. Remove long running transaction. Create processes which emulate real world because real world is not long running transaction.
A great site to learn more to create scalable architecture.

 
http://www.webperformancematters.com/journal/2007/8/10/five-scalability-principles.html

 
  1. Don’t think synchronously
  2. Don’t think vertically
  3. Don’t mix transactions with business intelligence
  4. Avoid mixing hot and cold data
  5. Don’t forget the power of memory

 

No comments:

Post a Comment