updated postgres and mongo updated

This commit is contained in:
2025-04-20 14:21:13 +03:00
parent 71822681f2
commit cc19cb7e6d
85 changed files with 6090 additions and 1986 deletions

View File

@@ -15,12 +15,12 @@ class Configs(BaseSettings):
Postgresql configuration settings.
"""
DB: str = ""
USER: str = ""
PASSWORD: str = ""
HOST: str = ""
PORT: str = 0
ENGINE: str = ""
DB: str = "postgres"
USER: str = "postgres"
PASSWORD: str = "password"
HOST: str = "10.10.2.14"
PORT: int = 5432
ENGINE: str = "postgresql+psycopg2"
POOL_PRE_PING: bool = True
POOL_SIZE: int = 20
MAX_OVERFLOW: int = 10
@@ -36,6 +36,6 @@ class Configs(BaseSettings):
model_config = SettingsConfigDict(env_prefix="POSTGRES_")
postgres_configs = (
Configs()
) # singleton instance of the POSTGRESQL configuration settings
# singleton instance of the POSTGRESQL configuration settings
postgres_configs = Configs()
print('url', postgres_configs.url)

View File

@@ -472,6 +472,74 @@ def run_all_tests():
return passed, failed
def run_simple_concurrent_test(num_threads=10):
"""Run a simplified concurrent test that just verifies connection pooling."""
import threading
import time
import random
from concurrent.futures import ThreadPoolExecutor
print(f"\nStarting simple concurrent test with {num_threads} threads...")
# Results tracking
results = {"passed": 0, "failed": 0, "errors": []}
results_lock = threading.Lock()
def worker(thread_id):
try:
# Simple query to test connection pooling
with EndpointRestriction.new_session() as db_session:
# Just run a simple count query
count_query = db_session.query(EndpointRestriction).count()
# Small delay to simulate work
time.sleep(random.uniform(0.01, 0.05))
# Simple success criteria
success = count_query >= 0
# Update results with thread safety
with results_lock:
if success:
results["passed"] += 1
else:
results["failed"] += 1
results["errors"].append(f"Thread {thread_id} failed to get count")
except Exception as e:
with results_lock:
results["failed"] += 1
results["errors"].append(f"Thread {thread_id} exception: {str(e)}")
# Create and start threads using a thread pool
start_time = time.time()
with ThreadPoolExecutor(max_workers=num_threads) as executor:
futures = [executor.submit(worker, i) for i in range(num_threads)]
# Calculate execution time
execution_time = time.time() - start_time
# Print results
print(f"\nConcurrent Operation Test Results:")
print(f"Total threads: {num_threads}")
print(f"Passed: {results['passed']}")
print(f"Failed: {results['failed']}")
print(f"Execution time: {execution_time:.2f} seconds")
print(f"Operations per second: {num_threads / execution_time:.2f}")
if results["failed"] > 0:
print("\nErrors:")
for error in results["errors"][:10]: # Show only first 10 errors to avoid flooding output
print(f"- {error}")
if len(results["errors"]) > 10:
print(f"- ... and {len(results['errors']) - 10} more errors")
return results["failed"] == 0
if __name__ == "__main__":
generate_table_in_postgres()
run_all_tests()
passed, failed = run_all_tests()
# If all tests pass, run the simple concurrent test
if failed == 0:
run_simple_concurrent_test(100)