NEST async VS sync

(yoav) #1

Using NEST in .net core 2.1
Is there any reason not to use async calls? For example (SearchAsync, DeleteIndexAsync, BulkAsync)
Should we always prefer async NEST methods over sync methods?

(Russ Cam) #2

Like most things in Software Development, "it depends" :slight_smile: Some non-exhaustive points to consider:

  1. Are blocking threads and synchronously waiting on HTTP requests to complete a measurable bottleneck in your application for concurrently handling requests?
  2. Does your application need to maintain a responsive UI whilst work is performed in the background?
  3. Do other dependencies you have only expose async code paths, forcing the viral nature of async throughout?

There is overhead to using async/await in terms of memory allocation, compiler generated state machines and typically a small performance hit. The benefit for largely I/O bound operations is asynchronous concurrency.

Ultimately, the best way to determine whether to use sync or async methods would be to benchmark both approaches in your application.

(system) closed #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.