Skip to content

Redis ConnectionPool

Redis
  • Schnell nachdem ich meinen Redis Stack Server auf eine VM ausgelagert hatte, stellte ich morgens beim Kaffee fest, das meine Flask Anwendung nicht mehr läuft. Mein PC ist meistens im Standby.

    broken pipe error (so in etwa)
    

    Um das zu beheben, musste ich jedes mal die Anwendung neu starten. Nervig! Das muss doch auch besser gehen und man müsste der Flask Anwendung das nur erklären 🙂

    Da man nicht alles wissen kann, nutze ich dann gerne für solche Fälle - ChatGPT Ich stellte also meine Frage und bekam das hier als Antwort.

    self.pool = redis.ConnectionPool(
                host=host,
                port=port,
                db=db,
                password=config.REDIS_PASSWORD,
                # Auto-Reconnect einstellen
                retry_on_timeout=True,
                # Optional: Weitere Einstellungen wie maximale Wiederverbindungsversuche,
                # Timeout-Werte, etc. können hier konfiguriert werden
                health_check_interval=30  # Überprüft die Verbindung alle 30 Sekunden
            )
    

    ChatGPT empfahl also einen Redis ConnectionPool anzulegen. In der ersten Antwort fehlte noch der health_check_interval, wie sich aber raus stellte ist der nötig.

    Somit sieht meine Datenbank Klasse wie folgt aus (nur der init Teil

    class PortfolioSettings:
    
        def __init__(self, host=config.SERVER_IP, port=6379, db=None):
            if db is None:  # If db is not provided explicitly, use TEST_MODE to decide
                if config.TEST_MODE == 1:
                    db = config.TEST[0]
                else:
                    db = config.LIVE[0]
    
            # Verwende einen Connection Pool
            self.pool = redis.ConnectionPool(
                host=host,
                port=port,
                db=db,
                password=config.REDIS_PASSWORD,
                # Auto-Reconnect einstellen
                retry_on_timeout=True,
                # Optional: Weitere Einstellungen wie maximale Wiederverbindungsversuche,
                # Timeout-Werte, etc. können hier konfiguriert werden
                health_check_interval=30  # Überprüft die Verbindung alle 30 Sekunden
            )
    
            self.client = redis.Redis(connection_pool=self.pool)
    

    Und damit funktioniert das bis jetzt sehr gut. Jetzt müsste ich nur noch wissen, wie der Redis ConnectionPool funktioniert!??

  • Die Antwort von ChatGPT wie der Redis ConnectionPool funktioniert. Ein paar Dinge finde ich komisch.

    https://chat.openai.com/share/b10fdadc-2c9b-404a-bc99-c883d110d6af

  • Portfolio - mein kleines Flask Projekt

    Python3
    5
    0 Stimmen
    5 Beiträge
    221 Aufrufe
    FrankMF
    Hab ChatGPT nochmal nach der Installation auf einem Production Server befragt. ChatGPT Certainly! Here's a short example of the steps you can follow to deploy a Flask application on a production server using Nginx and Gunicorn: Prepare your server: Set up a server (e.g., using a cloud provider like AWS, DigitalOcean, or a dedicated server) and ensure it has a clean, up-to-date installation of a Linux distribution (e.g., Ubuntu or CentOS). Install required software: Install necessary software packages on your server. You'll need Python, pip (Python package manager), Nginx, and Gunicorn. You can use your distribution's package manager (e.g., apt for Ubuntu or yum for CentOS) to install these dependencies. Deploy your Flask application: Copy your Flask application code and any required dependencies to your server. Set up a virtual environment (optional but recommended): Create a virtual environment for your Flask application to isolate its dependencies. You can use venv or virtualenv for this purpose. Install Flask and any required Python packages within your virtual environment: pip install flask Test your Flask application: Ensure your Flask application runs correctly within your server's virtual environment. Configure Gunicorn: Create a Gunicorn configuration file (e.g., gunicorn_config.py) to specify the settings for running your Flask application. Here's a simple example: workers = 4 # Number of Gunicorn worker processes bind = '0.0.0.0:8000' # The address and port Gunicorn should listen on Start Gunicorn: Start Gunicorn with your Flask application: gunicorn -c gunicorn_config.py your_app:app Configure Nginx: Create an Nginx server block (often located in /etc/nginx/sites-available) to define how Nginx should handle incoming requests. Here's a simplified example: server { listen 80; server_name your_domain.com www.your_domain.com; location / { proxy_pass http://127.0.0.1:8000; # Pass requests to Gunicorn proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } Enable the Nginx server block and restart Nginx: sudo ln -s /etc/nginx/sites-available/your_config /etc/nginx/sites-enabled/ sudo nginx -t # Test Nginx configuration sudo systemctl restart nginx Configure your DNS: Point your domain name to your server's IP address. Secure your server (optional but recommended): Set up SSL/TLS certificates for your domain to enable HTTPS. You can use Let's Encrypt for free SSL certificates. Monitor your application: Set up monitoring tools and logs to keep track of your application's performance and troubleshoot any issues. These are the basic steps to deploy a Flask application on a production server with Nginx and Gunicorn. Please note that this is a simplified example, and there are many additional considerations, such as database configuration, security, and optimization, depending on your specific application and requirements. It's also important to keep your server and software up to date and follow security best practices to ensure the stability and security of your production environment. Das werde ich doch mal ausprobieren
  • Open Source Software - Nur mit Luft & Liebe läuft es auch nicht rund

    Linux
    1
    0 Stimmen
    1 Beiträge
    145 Aufrufe
    Niemand hat geantwortet
  • Vaultwarden - SystemD

    Linux
    1
    0 Stimmen
    1 Beiträge
    205 Aufrufe
    Niemand hat geantwortet
  • 10G

    Linux
    2
    0 Stimmen
    2 Beiträge
    172 Aufrufe
    FrankMF
    Bedingt durch ein paar Probleme mit der Forensoftware, habe ich einen kleinen Datenverlust erlitten. Dazu gehören auch hier einige Beiträge. Dann versuche ich das mal zu rekonstruieren. Oben hatten wir das SFP+ Modul ja getestet. Als nächsten Schritt habe ich die ASUS XG-C100F 10G SFP+ Netzwerkkarte in meinen Hauptrechner verbaut. [image: 1635752117002-20211028_162455_ergebnis.jpg] Die Verbindung zum Zyxel Switch erfolgt mit einem DAC-Kabel. Im Video zum Zyxel Switch wurde schön erklärt, das die DAC Verbindung stromsparender als RJ45 Adapter sind. Somit fiel die Wahl auf die DAC Verbindungen. Hier nochmal das Video. https://www.youtube.com/watch?v=59I-RlliRms So sieht so ein DAC Verbindungskabel aus. Die SFP+ Adapter sind direkt daran montiert. [image: 1635752308951-20211028_170118_ergebnis.jpg] ethtool root@frank-MS-7C37:/home/frank# ethtool enp35s0 Settings for enp35s0: Supported ports: [ FIBRE ] Supported link modes: 100baseT/Full 1000baseT/Full 10000baseT/Full 2500baseT/Full 5000baseT/Full Supported pause frame use: Symmetric Receive-only Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 100baseT/Full 1000baseT/Full 10000baseT/Full 2500baseT/Full 5000baseT/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 10000Mb/s Duplex: Full Port: FIBRE PHYAD: 0 Transceiver: internal Auto-negotiation: on Supports Wake-on: pg Wake-on: g Current message level: 0x00000005 (5) drv link Link detected: yes iperf3 ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- Accepted connection from 192.168.3.207, port 44570 [ 5] local 192.168.3.213 port 5201 connected to 192.168.3.207 port 44572 [ ID] Interval Transfer Bitrate Retr Cwnd [ 5] 0.00-1.00 sec 1.10 GBytes 9.43 Gbits/sec 46 1.59 MBytes [ 5] 1.00-2.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.60 MBytes [ 5] 2.00-3.00 sec 1.10 GBytes 9.42 Gbits/sec 3 1.60 MBytes [ 5] 3.00-4.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.60 MBytes [ 5] 4.00-5.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.61 MBytes [ 5] 5.00-6.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.63 MBytes [ 5] 6.00-7.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.63 MBytes [ 5] 7.00-8.00 sec 1.09 GBytes 9.41 Gbits/sec 0 1.68 MBytes [ 5] 8.00-9.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.68 MBytes [ 5] 9.00-10.00 sec 1.10 GBytes 9.42 Gbits/sec 0 1.68 MBytes [ 5] 10.00-10.02 sec 22.5 MBytes 9.45 Gbits/sec 0 1.68 MBytes - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [ 5] 0.00-10.02 sec 11.0 GBytes 9.42 Gbits/sec 49 sender
  • Kopia - Kopia-Server mit Kopia-UI

    Kopia
    1
    2
    0 Stimmen
    1 Beiträge
    418 Aufrufe
    Niemand hat geantwortet
  • Kopia - Mounten einer Sicherung

    Verschoben Kopia
    1
    1
    0 Stimmen
    1 Beiträge
    215 Aufrufe
    Niemand hat geantwortet
  • Linux Umstieg - 6 Jahre

    Verschoben Allgemeine Diskussionen
    1
    1
    1 Stimmen
    1 Beiträge
    275 Aufrufe
    Niemand hat geantwortet
  • SSH Login ohne Passwort

    Angeheftet Linux
    4
    0 Stimmen
    4 Beiträge
    1k Aufrufe
    FrankMF
    Wie ihr ja wisst, benutze ich das Forum hier auch gerne als Notizbuch Also mal wieder was hier notieren. Mein Windows Systemadmin sagte mir heute, das es auch folgendes gibt # ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/root/.ssh/id_ed25519): /tmp/ed Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /tmp/ed Your public key has been saved in /tmp/ed.pub The key fingerprint is: SHA256:D33HCTW7Dy0p5kQdFTkPudx1PQh0EHFgkBvxy8KwhGM root@frank-ms7c92 The key's randomart image is: +--[ED25519 256]--+ | o=O*o=+=| | . oo o+oB+| | E o o.o.o+*| | . o +o...oo=o| | .So.o= O .| | o.= o + | | . . .| | | | | +----[SHA256]-----+ Der Key liegt nur in /tmp kopieren lohnt also nicht Ob das jetzt die Zukunft ist, kann ich nicht beantworten. Ich wollte es aber hier mal festhalten, weil es wohl mittlerweile auch von vielen Projekten benutzt wird. https://en.wikipedia.org/wiki/Ssh-keygen