Menu
Architectural decision Record 0004: STM for concurrency
ADR-0004: Implementation of Software Transactional Memory (STM) for Concurrency
Decision: Use Clojure's Software Transactional Memory (STM) for managing concurrent operations in FrankenScore, rather than simple atoms.
Context:
Rationale:
1. Coordinated Updates: STM allows for coordinated updates across multiple refs, which is essential for maintaining consistency in complex musical structures. Atoms, while useful for single-point updates, don't provide this level of coordination.
2. Automatic Retry Mechanism: STM provides an automatic retry mechanism for handling conflicts in concurrent modifications. This is superior to manual conflict resolution that would be necessary with atoms.
3. Atomicity: STM ensures that either all changes in a transaction are applied, or none are. This is crucial for operations that need to modify multiple parts of the musical structure atomically.
4. Composability: STM transactions are composable, allowing for the creation of larger atomic operations from smaller ones. This is particularly useful for complex musical operations that may involve multiple steps.
5. Scalability: STM is designed to scale well with multiple cores, automatically leveraging available processing power. This aligns with the system's goal of high-performance concurrent updates.
6. Deadlock Avoidance: STM helps avoid common concurrency pitfalls like deadlocks, which could be more challenging to manage with lower-level concurrency primitives.
Consequences:
Pros:
Cons:
Context:
- The system needs to handle complex, concurrent modifications to musical structures.
- Musical scores can be large and complex, potentially requiring multiple coordinated updates across different parts of the structure.
- Consistency and atomicity of operations are crucial for maintaining the integrity of musical data.
- The system aims to support high-performance concurrent updates (over 100,000 updates per second).
Rationale:
1. Coordinated Updates: STM allows for coordinated updates across multiple refs, which is essential for maintaining consistency in complex musical structures. Atoms, while useful for single-point updates, don't provide this level of coordination.
2. Automatic Retry Mechanism: STM provides an automatic retry mechanism for handling conflicts in concurrent modifications. This is superior to manual conflict resolution that would be necessary with atoms.
3. Atomicity: STM ensures that either all changes in a transaction are applied, or none are. This is crucial for operations that need to modify multiple parts of the musical structure atomically.
4. Composability: STM transactions are composable, allowing for the creation of larger atomic operations from smaller ones. This is particularly useful for complex musical operations that may involve multiple steps.
5. Scalability: STM is designed to scale well with multiple cores, automatically leveraging available processing power. This aligns with the system's goal of high-performance concurrent updates.
6. Deadlock Avoidance: STM helps avoid common concurrency pitfalls like deadlocks, which could be more challenging to manage with lower-level concurrency primitives.
Consequences:
Pros:
- Thread-safe operations with automatic conflict resolution.
- Simplified programming model for complex concurrent operations.
- High performance (over 100,000 updates per second achieved on vanilla laptop from 2017).
- Better consistency guarantees for complex musical structures.
Cons:
- Potential performance overhead for simple operations compared to atoms.
- Learning curve for developers not familiar with STM concepts.
|
FrankenScore is a modern, open-source music notation software designed to handle complex musical scores with ease. It is designed to be a flexible and powerful music notation software tool providing professional, extremely high-quality results. The core functionality includes inputting music notation, formatting scores and their parts, and printing them. Additional features can be added as plugins, allowing for a modular and customizable user experience.
|