Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mastering Web Application Configurations A Jour...

Mastering Web Application Configurations A Journey Through Nginx, uWSGI, and Flask with Knowledge Graphs.

Join us for an engaging 25-minute session and explore the creation of knowledge graphs. My focus is on the art of gathering information and using it effectively.

This time, I'll specifically look at configuration files.

Do you face these challenges?

Unsure about how to write configuration files
Experimenting with sample configurations from websites results in errors
Encountering occasional errors in configurations
Facing issues after upgrading to a new version
Many of these problems often stem from inadequate configurations, leading to situations where things stop working due to a lack of updated knowledge.

How do you typically try to resolve them?

Seek advice from knowledgeable individuals
Conduct web searches
Ask ChatGPT
While these approaches might work, they often consume a significant amount of time.

Now, imagine using a knowledge graph in this scenario:

Your knowledge becomes visible
Faster issue resolution
Adaptability to version upgrades
Let's try creating a knowledge database using open-source tools. For example, envision setting up Python for web applications with Nginx + uWSGI + Flask. Each component has its unique setup, adding a layer of complexity. Let's tackle the challenge of finding the optimal configuration, especially in the occasionally perplexing world of uWSGI options.

This session is primarily designed for beginners. I'll provide straightforward explanations to make the content easily understandable.

Koji Annoura

April 09, 2024
Tweet

More Decks by Koji Annoura

Other Decks in Technology

Transcript

  1. FOSSASIA 2024, Apr. 9 2024 14:20-14:45 Main Hall Mastering Web

    Application Configurations A Journey Through Nginx, uWSGI, and Flask with Knowledge Graphs. Koji Annoura ҊӜߒೋ [email protected] 4PVSDF/FPKIUUQTOFPKDPNVTFDBTFTLOPXMFEHFHSBQI
  2. Who am I ❖ Koji Annoura ❖ I live in

    Fukuoka Japan ❖ I love ❖ Apache Hop ❖ Data Orchestration App ❖ Apache User Group Japan ❖ I am a founder ❖ Neo4j Graph Database ❖ Neo4j Users Group Tokyo ❖ I am one of the founders. ❖ Graph Community MVP
  3. Agenda ❖ 1. Web App ❖ Flask ❖ uWSGI ❖

    2. Let's write a conf fi le for uWSGI. ❖ Ask ChatGPT ❖ 3. One of the good solutions ❖ Knowledge Graph
  4. u Web Server Gateway Interface (uWSGI) ❖ What is the

    correct pronunciation? ❖ 1. micro-whiskey ❖ 2. you-whizz-gee ❖ 3. mu-wiz-gee 4PVSDF/FPKIUUQTOFPKDPNVTFDBTFTLOPXMFEHFHSBQI
  5. Introduction ❖ Who loves .conf, .ini fi les? ❖ Yes,

    Easy to setup ❖ No, Dif fi cult to setup ❖ No, what’s the best setting ❖ It’s like RPG ❖ You cannot achieve the goal in one attempt ❖ Seek hints from the master 4PVSDF8JLJQFEJBIUUQTFOXJLJQFEJBPSHXJLJ1PLÉNPO
  6. Python Web App ❖ Which framework do you like? ❖

    Web Frameworks ❖ Full-Stack ❖ Django ❖ Web2py ❖ Non Full-Stack ❖ Flask ❖ CherryPy ❖ FastAPI 4PVSDF1BMMFUT1SPKFDUT IUUQTQBMMFUTQSPKFDUTDPNQ fl BTL
  7. Ruby Web App ❖ Please imagine that you are also

    working on a Ruby project. ❖ Web Frameworks ❖ Full-Stack ❖ Ruby on Rails 4PVSDF3VCZPO3BJMT IUUQTSVCZPOSBJMTPSH
  8. Java Web App ❖ Please imagine that you are also

    working on a Java project. ❖ Web Frameworks ❖ Spring Boot ❖ Play Framework 4PVSDF4QSJOH IUUQTTQSJOHJPQSPKFDUTTQSJOHCPPU
  9. If you have 3 different lang Web App ❖ How

    do users access the web sites? ❖ Web Server? ❖ Python ❖ Flask run (port: 5000?) ❖ Ruby ❖ Webrick (port: 3000?) ❖ Java ❖ Tomcat (port: 8080?)
  10. One Web Server ❖ This is a typical/traditional server con

    fi guration. ❖ Web Server ❖ Nginx ❖ Apache Web Server
  11. uWSGI ❖ In the case of Flask, it's common to

    use uWSGI. ❖ uWSGI ❖ Connects Nginx and Flask
  12. Traditional Problem-Solving Methods ❖ Traditional methods of resolving con fi

    guration issues: ❖ 1. Seeking advice from experts ❖ 2. Conducting web searches ❖ 3. Using AI assistants like ChatGPT 4PVSDF8JLJQFEJBIUUQTFOXJLJQFEJBPSHXJLJ1SPCMFN@TPMWJOH
  13. Teach me how to connect Nginx and Flask? ❖ The

    simplest connection ❖ ChatGPT ❖ To connect Nginx and a Flask app, you typically use Nginx as a reverse proxy server. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  14. How about using uWSGI? ❖ Common connections ❖ ChatGPT ❖

    Using uWSGI with Nginx is a common setup for deploying Flask applications in production environments. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  15. .ini File for uWSGI ❖ Simple con fi guration fi

    le ❖ ChatGPT ❖ You can do this by creating a con fi guration fi le for uWSGI (e.g., app.ini) ɹ with theɹ following content. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  16. .ini File for uWSGI ❖ Simple con fi guration fi

    le ❖ ChatGPT ❖ You can do this by creating a con fi guration fi le for uWSGI (e.g., app.ini) ɹ with theɹ following content. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  17. How do I automatically reload when the app changes? ❖

    Add option ❖ ChatGPT ❖ you can use uWSGI's --py-autoreload option. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  18. virtual environment (venv). ❖ ChatGPT ❖ If you're encountering issues

    with uWSGI's auto- reload feature while using a virtual environment (venv). 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  19. Correct settings for virtual environment (venv)? ❖ ChatGPT ❖ If

    you're encountering issues with uWSGI's auto- reload feature while using a virtual environment (venv), it's likely due to the way uWSGI is detecting fi le changes within the virtual environment. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  20. Is virtualenv or venv correct than pythonpath. ❖ ChatGPT ❖

    You're correct. Using virtualenv or venv to isolate the Python environment is indeed a more common and preferred approach compared to specifying the Python executable directly with pythonpath. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  21. What options should I add to my ini setup? ❖

    ChatGPT ❖ Here's a list of commonly used options along with their descriptions: 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  22. The “socket-backlog” uWSGI option is correct? ❖ ChatGPT ❖ The

    socket-backlog option in uWSGI determines the maximum number of connections that the operating system will queue for your application when the application is handling too many connections to keep up with. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  23. I can't find the “socket-backlog” option. ❖ ChatGPT ❖ I

    apologize for the confusion. You're correct; there isn't a socket-backlog option in uWSGI. 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  24. Hallucination (artificial intelligence) ❖ Have you ever been troubled by

    incorrect answers from AI? ❖ Hallucination or arti fi cial hallucination is a response generated by AI which contains false or misleading information presented as fact. 4PVSDF8JLJQFEJB IUJUQTFOXJLJQFEJBPSHXJLJ)BMMVDJOBUJPO@ BSUJ fi DJBM@JOUFMMJHFODF
  25. How can one resolve hallucinations? ❖ Waiting for the next

    version. ❖ Look for another better AI. ❖ Stop using AI.
  26. One of Solutions (LLM + Knowledge Graph) ❖ Return True

    Facts ❖ Neo4j’s knowledge graph grounds LLM responses in validated facts using retrieval augmented generation (RAG). Easily add and update data, indexes, and RAG sources with our developer friendly schema that never requires redesign. Graph structure makes fi nding factual answers to multi-hop questions possible through traversals that follow a breadcrumb trail of connections. 4PVSDF/FPKIUUQTOFPKDPNHFOFSBUJWFBJ
  27. Knowledge Graphs? ❖ knowledge graph ❖ is a knowledge base

    that uses a graph- structured data model or topology to represent and operate on data. 4PVSDF8JLJQFEJB IUUQTFOXJLJQFEJBPSHXJLJ,OPXMFEHF@HSBQI
  28. Graph Database ❖ 3 Components ❖ Nodes (Records) ❖ Relationships

    (Related tables) ❖ Properties (item) 4PVSDF%#&OHJOFT IUUQTECFOHJOFTDPNFOSBOLJOHHSBQI ECNT
  29. (:Movie)—(:Person) ❖ Nodes ❖ Movie (38) ❖ Person (133) ❖

    Relationship ❖ ACTED_IN ❖ DIRECTED ❖ PRODUCED ❖ WROTE ❖ FOLLOWD ❖ REVIEWED
  30. Matrix, (:Movie)—(:Person)—(:Movie)—(:Person) ❖ Nodes ❖ Movie (38) ❖ Person (133)

    ❖ Relationship ❖ ACTED_IN ❖ DIRECTED ❖ PRODUCED ❖ WROTE ❖ FOLLOWD ❖ REVIEWED
  31. Matrix, (:Movie)—(:Person) ❖ Nodes ❖ Movie (3) ❖ Person (8)

    ❖ Relationship ❖ ACTED_IN ❖ DIRECTED ❖ PRODUCED ❖ WROTE ❖ FOLLOWD ❖ REVIEWED
  32. Matrix, (:Movie)—(:Person)—(:Movie)—(:Person) ❖ Nodes ❖ Movie (11) ❖ Person (44)

    ❖ Relationship ❖ ACTED_IN ❖ DIRECTED ❖ PRODUCED ❖ WROTE ❖ FOLLOWD ❖ REVIEWED
  33. uWSGI Options ❖ Options ❖ 1, uWSGI core ❖ 2,

    plugin: airbrake ❖ 3, plugin: alarm_curl ❖ 4, plugin: alarm_speech ❖ 5, plugin: alarm_xmpp ❖ ... ❖ 123, plugin: xslt ❖ 124, plugin: zabbix ❖ 125, plugin: zergpool
  34. uWSGI Options ❖ Options ❖ 1, uWSGI core ❖ 2,

    plugin: airbrake ❖ 3, plugin: alarm_curl ❖ 4, plugin: alarm_speech ❖ 5, plugin: alarm_xmpp ❖ ... ❖ 123, plugin: xslt ❖ 124, plugin: zabbix ❖ 125, plugin: zergpool
  35. uWSGI Options to Neo4j Graph Database ❖ Nodes ❖ Category

    (1) ❖ Type (125) ❖ Option (1254) ❖ Relationship ❖ TYPE ❖ OPTION
  36. uWSGI Options (1254) ❖ Nodes ❖ Category (1) ❖ Type

    (125) ❖ Option (1254) ❖ Relationship ❖ TYPE ❖ OPTION
  37. uWSGI Options ❖ Nodes ❖ Category (1) ❖ Type (125)

    ❖ Option (1254) ❖ Relationship ❖ TYPE ❖ OPTION
  38. Only the correct options are set w/Knoledge Graph ❖ LLM

    + Knowledge Graph 4PVSDF0QFO"* IUUQTDIBUPQFOBJDPN
  39. You can add “Same as” relationships ❖ 4 diff option

    names ❖ plugin:python ❖ pyhome (-H) ❖ virtualenv (-H) ❖ home (-H) ❖ venv (-H) ❖ You can merge them into one option name.
  40. You can add “Check it” relationships ❖ No logs ❖

    disable-logging = true ❖ But you need some log ❖ log-4xx = true ❖ log-5xx = true ❖ log-ioerror = true
  41. Ground LLMs with Knowledge Graph ❖ Deep Partnerships with Generative

    AI Providers ❖ https://neo4j.com/generativeai/ 4PVSDF/FPK IUUQTOFPKDPNHFOFSBUJWFBJ
  42. Conclusion ❖ The advancement of AI is remarkable. ❖ But

    ❖ Knowledge Graphs are particularly effective for representing facts. 4PVSDF/FPK IUUQTOFPKDPNHFOFSBUJWFBJ