weaviate-python-client icon indicating copy to clipboard operation
weaviate-python-client copied to clipboard

The `Timeout(insert)` parameter determines startup timeout threshold

Open databyjp opened this issue 1 year ago • 0 comments

Due to the client polling /v1/.well-known/openid-configuration to determine the OIDC config, the now-default 90s timeout for insert operations seem to dictate the timeout period for the client.

It may be preferable to set a separate parameter, or use the init value.

Script to reproduce (vary the insert parameter):

import socket
import time
import threading
import weaviate
from weaviate.classes.init import Timeout, AdditionalConfig
import time

def server_thread(stop_event):
    # Create a TCP/IP socket
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_address = ('localhost', 12345)
    server_socket.bind(server_address)
    server_socket.listen(1)

    # print('Server listening on {}:{}'.format(*server_address))

    while not stop_event.is_set():
        # print('Waiting for a connection...')
        try:
            connection, client_address = server_socket.accept()
        except OSError:
            # Handle potential socket error when shutting down
            break

        try:
            # print('Connection from', client_address)

            # Receive data and simulate a delay
            data = connection.recv(1024)
            # print('Received:', data)
            time.sleep(100)  # Simulate 100 second black hole

            # Do not send a response
        finally:
            connection.close()

    server_socket.close()
    # print('Server stopped')
    return True


def run_weaviate():
    for (port, grpc_port, timeout) in [
        (8080, 50051, 2), # Correct
        (12345, 50051, 2), # REST Black hole
        (8080, 12345, 2), # gRPC Black hole
        (1111, 50051, 2), # Incorrect REST
        (8080, 1111, 2), # Incorrect gRPC
    ]:
        print(f"\n")
        print(f"=" * 80)
        print(f"port={port}, grpc_port={grpc_port}, timeout={timeout}")
        print(f"=" * 80)
        print(f"\n")
        starttime = time.time()
        try:
            client = weaviate.connect_to_local(
                port=port,
                grpc_port=grpc_port,
                additional_config=AdditionalConfig(
                    timeout=Timeout(init=timeout, insert=5)  # Set grpc timeout to 2 seconds, rest timeout to 5 seconds
                )
            )

            assert client.is_ready()
            print("Weaviate is ready")
            client.close()
        except Exception as e:
            print(e)
        print("Time taken: ", time.time() - starttime)
    return True


if __name__ == '__main__':
    stop_event = threading.Event()
    server_thread = threading.Thread(target=server_thread, args=(stop_event,))
    server_thread.start()

    run_weaviate()

    # Set the event to stop the server thread
    stop_event.set()
    server_thread.join()
    print('Main script finished')

databyjp avatar Apr 23 '24 15:04 databyjp