Background Tasks and Thread Pools in Microservices

In this chapter, you'll learn how to use background tasks in microservices. In Chapter 5Understanding Asynchronous Operations with the Futures Crate, we created a microservice that provides a feature that enables the user to upload images. Now, we'll create another version of this service, which loads an image and returns a resized version of that image.

To utilize the available resources fully, microservices have to be implemented with asynchronous code, but not every part of a microservices can be asynchronous. For example, parts that require massive CPU load or parts that have to use shared resources should be implemented in a separate thread or use a pool of threads to avoid blocking the main threads that are used to process the event loops used by asynchronous code.

In this chapter, we'll cover the following topics:

  • How to interact with spawned threads
  • How to use the futures-cpupool and tokio-threadpool crates
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.211.106