arbyazra123 commited on
Commit
b615834
·
1 Parent(s): d1a85d8

support multiple instance of vect search

Browse files
Files changed (1) hide show
  1. vdb/api.py +61 -5
vdb/api.py CHANGED
@@ -458,23 +458,69 @@ def benchmark():
458
 
459
  # ==================== Main ====================
460
  if __name__ == "__main__":
 
 
461
  port = 9999
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  print("\n🚀 Starting Sumobot Milvus API server...")
463
  print(f"📡 Server will be available at: http://0.0.0.0:{port}")
 
464
  print(f"📚 API docs: http://0.0.0.0:{port}/docs")
465
  print(f"🔍 Health check: http://0.0.0.0:{port}/health")
466
  print(f"📊 Stats: http://0.0.0.0:{port}/stats")
467
  print("\n" + "="*70 + "\n")
468
-
 
 
469
  uvicorn.run(
470
- app,
471
  host="0.0.0.0",
472
  port=port,
473
- log_level="info"
 
 
474
  )
475
 
476
- # ==================== Test Commands ====================
477
- f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  # Health check
479
  curl http://localhost:9999/health
480
 
@@ -511,4 +557,14 @@ curl http://localhost:9999/benchmark
511
 
512
  # Interactive API docs
513
  # Open in browser: http://localhost:9999/docs
 
 
 
 
 
 
 
 
 
 
514
  """
 
458
 
459
  # ==================== Main ====================
460
  if __name__ == "__main__":
461
+ import sys
462
+
463
  port = 9999
464
+ workers = 20 # Number of worker processes
465
+
466
+ # Check if running with multiple workers
467
+ if "--workers" in sys.argv:
468
+ try:
469
+ workers_idx = sys.argv.index("--workers")
470
+ workers = int(sys.argv[workers_idx + 1])
471
+ except (IndexError, ValueError):
472
+ print("⚠️ Invalid --workers argument, using default: 20")
473
+
474
+ if "--port" in sys.argv:
475
+ try:
476
+ port_idx = sys.argv.index("--port")
477
+ port = int(sys.argv[port_idx + 1])
478
+ except (IndexError, ValueError):
479
+ print(f"⚠️ Invalid --port argument, using default: {port}")
480
+
481
  print("\n🚀 Starting Sumobot Milvus API server...")
482
  print(f"📡 Server will be available at: http://0.0.0.0:{port}")
483
+ print(f"👷 Workers: {workers}")
484
  print(f"📚 API docs: http://0.0.0.0:{port}/docs")
485
  print(f"🔍 Health check: http://0.0.0.0:{port}/health")
486
  print(f"📊 Stats: http://0.0.0.0:{port}/stats")
487
  print("\n" + "="*70 + "\n")
488
+
489
+ # For production with multiple workers, use uvicorn with workers parameter
490
+ # Each worker will have its own connection to Milvus
491
  uvicorn.run(
492
+ "api:app", # Use string import path for workers to work properly
493
  host="0.0.0.0",
494
  port=port,
495
+ workers=workers,
496
+ log_level="info",
497
+ access_log=True
498
  )
499
 
500
+ # ==================== Usage Instructions ====================
501
+ """
502
+ # ==================== Running the Server ====================
503
+
504
+ # Run with 20 workers (default)
505
+ python vdb/api.py
506
+
507
+ # Run with custom number of workers
508
+ python vdb/api.py --workers 10
509
+
510
+ # Run with custom port
511
+ python vdb/api.py --port 8000 --workers 20
512
+
513
+ # Alternative: Using Gunicorn for production (install: pip install gunicorn)
514
+ gunicorn vdb.api:app \
515
+ --workers 20 \
516
+ --worker-class uvicorn.workers.UvicornWorker \
517
+ --bind 0.0.0.0:9999 \
518
+ --timeout 120 \
519
+ --access-logfile - \
520
+ --error-logfile -
521
+
522
+ # ==================== Testing the API ====================
523
+
524
  # Health check
525
  curl http://localhost:9999/health
526
 
 
557
 
558
  # Interactive API docs
559
  # Open in browser: http://localhost:9999/docs
560
+
561
+ # ==================== Performance Testing ====================
562
+
563
+ # Load test with Apache Bench (install: brew install httpd or apt-get install apache2-utils)
564
+ ab -n 10000 -c 100 -T 'application/json' \
565
+ -p query.json \
566
+ http://localhost:9999/query
567
+
568
+ # Where query.json contains:
569
+ # {"state": "AngleToEnemy=7.77, AngleToEnemyScore=0.99, DistanceToEnemyScore=0.76, NearBorderArenaScore=0.81, FacingToArena=-0.99"}
570
  """