zoukankan      html  css  js  c++  java
  • What are some advantages of using Node.js over a Flask API?

    https://www.quora.com/What-are-some-advantages-of-using-Node-js-over-a-Flask-API

    Flask is a Python web microframework. It needs to be run behind a WSGI compliant web server. The nature of WSGI is synchronous. So you'll usually spawn threads to serve requests. Python 'threads' is also blocking, due to the GIL, they cannot run in parallel. Thus reducing the number of requests you're able to be served. Spawning threads is also expensive.

    NodeJS is not a framework, it's a JavaScript binding of libuv. I have a write up about it over here:

    Under The Bonnet 1 - NodeJS - YKode

    NodeJS is asynchronous by design. Which means that it's not blocking.  When you you do I/O it will return immediately and get notification later on. It's single threaded. It just means that you won't block the event loop when you wait for response, you can do another task including accepting incoming requests.  So even on single thread, you can accept and serve multiple requests. On synchronous environment, this I/O operation will block the thread.

    The event driven and concurrent connections model of Node.js makes it one of the best platforms for real time applications like online games, collaboration tools, chat rooms, or anything where what one user (or robot? or sensor?) does with the application needs to be seen by other users immediately, without a page refresh.

    As this answer on Stack Overflow says,

    My feeling is that Node.js is especially suited for applications where you'd like to maintain a persistent connection from the browser back to the server. Using a technique known as "long-polling", you can write an application that sends updates to the user in real time. Doing long polling on many of the web's giants, like Ruby on Rails or Django, would create immense load on the server, because each active client eats up one server process. This situation amounts to a tarpit attack. When you use something like Node.js, the server has no need of maintaining separate threads for each open connection.


    Although, there exist libraries in Python as well for doing this sort of work, Node.js does it really well (powered by cutting edge V8 JavaScript engine). However, if you are performing some heavy server side computation on receiving requests, then you are better off serving it with regular FLASK based server. (subjective comment)

     

     

     

  • 相关阅读:
    HDU:2767-Proving Equivalences(添边形成连通图)
    POJ:1330-Nearest Common Ancestors(LCA在线、离线、优化算法)
    HDU:1269-迷宫城堡(tarjan模板)
    Xml 丶json丶 C/S KVO 数据库 SQL 数据持久化 复杂对象 集合视图综合
    项目穿越记
    SDP (Session Description Protocol)
    shell脚本实现查找文件夹下重复的文件,并提供删除功能
    HDU 2896 病毒侵袭 (AC自动机)
    项目启动那些事儿
    C++ 完美破解九宫格(数独)游戏
  • 原文地址:https://www.cnblogs.com/rsapaper/p/8179496.html
Copyright © 2011-2022 走看看