Skip to content

WIP: Handle retry-after header#65

Closed
tellet-q wants to merge 1 commit intomasterfrom
retry-after-header
Closed

WIP: Handle retry-after header#65
tellet-q wants to merge 1 commit intomasterfrom
retry-after-header

Conversation

@tellet-q
Copy link
Contributor

@tellet-q tellet-q commented Mar 17, 2025

Add support for following responses from Qdrant:

Rate limiter hit for gRPC: qdrant/qdrant#6072

Usage example for strict mode ("read_rate_limit": 60, "write_rate_limit": 60):

package org.example;

import io.grpc.StatusRuntimeException;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.ResourceExhaustedException;
import io.qdrant.client.grpc.Points;

import java.util.List;
import java.util.concurrent.ExecutionException;

public class Main {
    public static void hitRateLimit(QdrantClient qClient) {
        System.out.println("start hitRateLimit");
        for (int i = 0; i < 100; i++) {
            try {
                List<Points.ScoredPoint> points =
                  qClient
                    .searchAsync(
                      Points.SearchPoints.newBuilder()
                        .setCollectionName("benchmark")
                        .addAllVector(List.of(0.6235f, 0.123f, 0.532f, 0.123f))
                        .setLimit(5)
                        .build())
                    .get();
            } catch (ExecutionException | InterruptedException | StatusRuntimeException e) {
                    System.out.println("Exception caught: " + e.getMessage());
                    if (e.getCause() instanceof ResourceExhaustedException) {
                        ResourceExhaustedException ex = (ResourceExhaustedException) e.getCause();
                        System.out.println("hitRateLimit! retry after" + ex.getRetryAfterSeconds());
                        break;
                    }
                    break;
                }
        }
        System.out.println("done hitRateLimit");
    }

    public static void main(String[] args) {
        QdrantClient client = new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false, true).build());

        String collectionName = "benchmark";

        try {
            client.healthCheckAsync().get();
            boolean collectionExists = client.collectionExistsAsync(collectionName).get();

            if (collectionExists) {
                System.out.println("Collection exists: " + collectionName);
            } else {
                System.out.println("Collection does not exist: " + collectionName);
            }
        } catch (Exception e) {
            System.err.println("Error checking collection: " + e.getMessage());
        }

        hitRateLimit(client);
    }
}

@tellet-q tellet-q requested a review from Anush008 March 17, 2025 14:24
@Anush008 Anush008 marked this pull request as draft March 19, 2025 07:54
@tellet-q tellet-q closed this Mar 20, 2025
@tellet-q tellet-q deleted the retry-after-header branch March 20, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant