Observability Done Right: Best Practices and Anti-Patterns for Effective System Monitoring

Image
  WHAT Observability is a concept that refers to the ability to gain insights into the behavior and performance of complex systems. In the context of software engineering, observability involves the collection, analysis, and visualization of data from software applications, infrastructure, and other components of a system. In the animal kingdom, observability plays a critical role in survival, allowing animals to monitor their surroundings, detect threats, and find food. Dolphins use echolocation to observe their surroundings. They emit high-frequency sounds that bounce off objects, allowing them to create a 3D map of their environment. Thanks for reading Knowledge Cafe! Subscribe for free to receive new posts and support my work. Subscribed WHY In today's era, architectures are becoming increasingly large, complex, and fast-paced due to the faster development and deployment of software by distributed teams with the help of DevOps, continuous delivery, and agile development methodo...

Facts about HashMap in Java 6

 


Few points regarding HashMap DS in Java 6 as per the source code.

HashMap extends AbstractMap implements Map

  • Backed by array of Map.Entry where each element points to a list of Map.Entry

  •  Default Initial Capacity – 16 i.e. Entry[16]

  • Default load factor  - 0.75 i.e. when size reaches 75% of capacity – resizing of internal data structure is triggered.

  • Capacity is always in power of 2 - if 5 is passed as initialCapacity in constructor, capacity will be set to 8 – it just does bitwise shift of 1 until it gets a number just greater than the passed capacity value.

  • If 8 is passed – actual capacity will be 16. (for detail check source code)

  • provides a hook method init() which subclasses can use for addition functionality- it is invoked from constructor.
  • modCount member variable to track the modifications in hashmap. same is used for Fail-fast detection

  • modifications means adding new Entry and removing Entry  from hashmap
  • provide supplement hash() to reduce collision (see documentation for more detail)

  • allows one null key and multiple null values.
  • for adding new entry, uses hashcode() of key, call hash() for defending poor hashcode, get index of Entry Array (called bucket), adds to the list in bucket.

  • when threshold crosses, resize() is invoked with new capacity generally twice the oldCapacity.

  • resize() creates a new Entry Array and transfer all Entry from old to new array.
  • Iteration is possible on key, value and Entry (internally has 3 iterator class namely KeyIterator, ValueIterator and EntryIterator. all extends abstract HashIterator private class)

  • keySet() and entrySet() returns Set object having iterator() method, which return appropriate instance of above mentioned iterator class.

  • values() return a collection instance which has iterator() method returning instance of ValueIterator class.
  • HashMap is not thread-safe. Need external synchronization or consider using Collections.synchronizedMap(new HashMap<Object,Object>())

  • No ordering for iteration - does a sequential scan based on index and list of Entry Array which may change on resizing().



Popular posts from this blog

Chain of responsibility using Spring @Autowired List

Iterate Through a HashMap

Under the Hood: Understanding the Gossip Protocol in Apache Cassandra