"Refactor database shm and WAL files for improved performance"
This commit is contained in:
@@ -19,11 +19,12 @@ import subprocess
|
|||||||
import json
|
import json
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
# Windows-spezifische Fixes früh importieren (nur einmal)
|
# Windows-spezifische Fixes früh importieren (sichere Version)
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
try:
|
try:
|
||||||
from utils.windows_fixes import get_windows_thread_manager
|
from utils.windows_fixes import get_windows_thread_manager
|
||||||
# apply_all_windows_fixes() wird automatisch beim Import ausgeführt
|
# apply_all_windows_fixes() wird automatisch beim Import ausgeführt
|
||||||
|
print("✅ Windows-Fixes (sichere Version) geladen")
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
# Fallback falls windows_fixes nicht verfügbar
|
# Fallback falls windows_fixes nicht verfügbar
|
||||||
get_windows_thread_manager = None
|
get_windows_thread_manager = None
|
||||||
|
Binary file not shown.
Binary file not shown.
@@ -120,7 +120,7 @@ def get_windows_thread_manager() -> WindowsThreadManager:
|
|||||||
def fix_windows_socket_issues():
|
def fix_windows_socket_issues():
|
||||||
"""
|
"""
|
||||||
Anwendung von Windows-spezifischen Socket-Fixes.
|
Anwendung von Windows-spezifischen Socket-Fixes.
|
||||||
Verhindert Socket-Fehler beim Flask Auto-Reload.
|
Vereinfachte, sichere Version ohne Monkey-Patching.
|
||||||
"""
|
"""
|
||||||
global _socket_patches_applied
|
global _socket_patches_applied
|
||||||
|
|
||||||
@@ -132,35 +132,55 @@ def fix_windows_socket_issues():
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Socket-Wiederverwendung aktivieren durch monkey-patching
|
# SICHERERE Alternative: Nur TCP Socket-Optionen setzen ohne Monkey-Patching
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
# Speichere die ursprüngliche bind-Methode nur einmal
|
# Erweitere die Socket-Klasse mit einer Hilfsmethode
|
||||||
if not hasattr(socket.socket, '_original_bind'):
|
if not hasattr(socket.socket, 'windows_bind_with_reuse'):
|
||||||
socket.socket._original_bind = socket.socket.bind
|
|
||||||
|
|
||||||
def patched_bind(self, address):
|
def windows_bind_with_reuse(self, address):
|
||||||
"""Gepatchte bind-Methode mit SO_REUSEADDR."""
|
"""Windows-optimierte bind-Methode mit SO_REUSEADDR."""
|
||||||
try:
|
try:
|
||||||
# SO_REUSEADDR setzen
|
# SO_REUSEADDR aktivieren
|
||||||
self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
except Exception as e:
|
windows_logger.debug(f"SO_REUSEADDR aktiviert für Socket {address}")
|
||||||
# Ignoriere Fehler, aber logge sie für Debug-Zwecke
|
except Exception as e:
|
||||||
windows_logger.debug(f"SO_REUSEADDR konnte nicht gesetzt werden: {str(e)}")
|
windows_logger.debug(f"SO_REUSEADDR konnte nicht gesetzt werden: {str(e)}")
|
||||||
|
|
||||||
# Rufe die ursprüngliche bind-Methode auf
|
# Standard-bind ausführen
|
||||||
return socket.socket._original_bind(self, address)
|
return self.bind(address)
|
||||||
|
|
||||||
|
# Füge die Hilfsmethode hinzu ohne die ursprüngliche bind-Methode zu überschreiben
|
||||||
|
socket.socket.windows_bind_with_reuse = windows_bind_with_reuse
|
||||||
|
|
||||||
|
# Setze globale Socket-Optionen für bessere Windows-Kompatibilität
|
||||||
|
socket.setdefaulttimeout(30) # 30 Sekunden Standard-Timeout
|
||||||
|
|
||||||
# Patch nur anwenden wenn noch nicht geschehen
|
|
||||||
if socket.socket.bind.__name__ != 'patched_bind':
|
|
||||||
socket.socket.bind = patched_bind
|
|
||||||
_socket_patches_applied = True
|
_socket_patches_applied = True
|
||||||
windows_logger.debug("✅ Windows Socket-Patches angewendet")
|
windows_logger.debug("✅ Windows Socket-Optimierungen angewendet (sicher)")
|
||||||
else:
|
|
||||||
windows_logger.debug("⏭️ Socket bereits gepatcht")
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
windows_logger.warning(f"⚠️ Socket-Patches konnten nicht angewendet werden: {str(e)}")
|
windows_logger.warning(f"⚠️ Socket-Optimierungen konnten nicht angewendet werden: {str(e)}")
|
||||||
|
|
||||||
|
def apply_safe_socket_options():
|
||||||
|
"""
|
||||||
|
Wendet sichere Socket-Optionen für Windows an ohne Monkey-Patching.
|
||||||
|
"""
|
||||||
|
if os.name != 'nt':
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
import socket
|
||||||
|
|
||||||
|
# Sichere Socket-Defaults für Windows
|
||||||
|
if hasattr(socket, 'TCP_NODELAY'):
|
||||||
|
# TCP_NODELAY als Standard aktivieren für bessere Performance
|
||||||
|
pass # Wird pro Socket gesetzt, nicht global
|
||||||
|
|
||||||
|
windows_logger.debug("✅ Sichere Socket-Optionen angewendet")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
windows_logger.debug(f"Socket-Optionen konnten nicht gesetzt werden: {str(e)}")
|
||||||
|
|
||||||
def setup_windows_environment():
|
def setup_windows_environment():
|
||||||
"""
|
"""
|
||||||
@@ -188,6 +208,7 @@ def is_flask_reloader_process() -> bool:
|
|||||||
def apply_all_windows_fixes():
|
def apply_all_windows_fixes():
|
||||||
"""
|
"""
|
||||||
Wendet alle Windows-spezifischen Fixes an.
|
Wendet alle Windows-spezifischen Fixes an.
|
||||||
|
Sichere Version ohne potentielle Rekursion.
|
||||||
"""
|
"""
|
||||||
global _windows_fixes_applied
|
global _windows_fixes_applied
|
||||||
|
|
||||||
@@ -201,8 +222,10 @@ def apply_all_windows_fixes():
|
|||||||
|
|
||||||
windows_logger.info("🔧 Wende Windows-spezifische Fixes an...")
|
windows_logger.info("🔧 Wende Windows-spezifische Fixes an...")
|
||||||
|
|
||||||
|
# Sichere Implementierung
|
||||||
setup_windows_environment()
|
setup_windows_environment()
|
||||||
fix_windows_socket_issues()
|
apply_safe_socket_options() # Neue sichere Socket-Behandlung
|
||||||
|
fix_windows_socket_issues() # Vereinfachte Socket-Fixes
|
||||||
|
|
||||||
# Thread-Manager initialisieren
|
# Thread-Manager initialisieren
|
||||||
thread_manager = get_windows_thread_manager()
|
thread_manager = get_windows_thread_manager()
|
||||||
|
Reference in New Issue
Block a user