top of page
Buscar

🌐 MAWESI: Tackling complex challenges globally with expertise to exceed expectations. 💡

Recently, we faced a challenge that required us to parallelize order processing. Here's a step-by-step breakdown of how our skilled team overcame this challenge using cutting-edge technology:


Scoped Lifetime Configuration: We modified dependency injection settings to use the Scoped Lifetime pattern, allowing each thread to have its own DbContext and avoiding concurrent access conflicts in the database. The main thread creates a thread manager responsible for creating and managing execution threads. Each thread created by the thread manager has its own DbContext, thanks to the Scoped Lifetime configuration. In this way, each thread accesses the database independently, without generating concurrent access conflicts.




Thread-Safe Singleton with SemaphoreSlim: We created a thread-safe Singleton class using SemaphoreSlim to orchestrate the processing, ensuring the prevention of multiple instance creation in a multithreaded environment.



Database Query Optimization: Our team optimized database queries to avoid prolonged execution times, thereby minimizing the risk of deadlocks due to high concurrency. We focused on SELECT, INSERT, and UPDATE statements, as well as stored procedures executed using Entity Framework. Some of the key optimizations included:


​1

​Utilizing AsNoTracking for read-only queries to reduce overhead and improve performance.

2

Applying indexes on frequently accessed columns and implementing covering indexes for specific queries.

3

Using batch operations for INSERT and UPDATE statements to minimize round trips to the database.

4

Leveraging projection queries with Select to retrieve only the required columns from the database, reducing the amount of data transferred.

5

Implementing pagination to retrieve data in smaller chunks, improving response times and reducing memory usage.

6

Optimizing stored procedures by identifying and eliminating bottlenecks using query execution plans and SQL Profiler.

By incorporating these optimizations an


d executing these strategies, we substantially enhanced the performance and scalability of our system. This enables it to accommodate increased workloads while maintaining a seamless user experience. Furthermore, we bolstered our solution's efficiency and reliability, ensuring that our system can adeptly manage high concurrency and consistently deliver outstanding performance.




Exponential Backoff Mechanism: Recognizing that deadlocks are inevitable in high-concurrency systems, we implemented an exponential backoff mechanism to monitor deadlocks and dynamically adjust the number of parallel processing threads.



Race Condition Resolution: During initial testing, we identified a race condition when requeueing an order for processing. This occasionally caused a less-updated order to overwrite a more recent one. We resolved this issue by prioritizing orders by status and ensuring the process didn't proceed to the next priority without completing the previous one. By implementing a proper synchronization mechanism, we ensured that orders were processed seamlessly and efficiently, enhancing the overall system's reliability and performance.


At MAWESI, we pride ourselves on our ability to deliver efficient, tailored solutions to diverse clients across different sectors. Our deep understanding of technology and commitm


ent to professionalism make us a reliable partner for businesses looking to overcome challenges and reach new heights.


If you're searching for a partner with technical expertise to help you navigate complex


challenges and deliver efficient, innovative solutions, look no further than MAWESI. Let's join forces and build a brighter future for your business! 🔧🌐



33 visualizaciones0 comentarios

Entradas Recientes

Ver todo
bottom of page