microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
93 stars 68 forks source link

Reactive with Spring Data REST cosmos DB #529

Closed tanayamitra05 closed 4 years ago

tanayamitra05 commented 4 years ago

Is there any significant time difference for fetching data by using Flux in reactive and normal List Collection in Java?

kushagraThapar commented 4 years ago

Depends on your use case, if fetching data using Flux is done in a completely asynchronous way, then that would be ideal and fastest. Otherwise, if using blocking calls, its effectively same as using normal list collection in java.

tanayamitra05 commented 4 years ago

I am fetching the data like: Flux cmLogs = cmLogsRepository.findAll(); return cmLogs;

and the repository code: public interface CMLogsRepository extends ReactiveCosmosRepository<CentralizedManagementEntity, String> { Flux findAllById(String id);

But there is no such timing difference in this case.

kushagraThapar commented 4 years ago

@tanayamitra05 when you run reactive code like this : Flux<T> cmLogs = cmLogsRepository.findAll(); it doesn't execute the find all operation at this point until you subscribe to it. So measuring timing at this point doesn't even makes sense.

Please read project reactor docs for more details on how to run reactive asynchronous code. https://projectreactor.io/learn