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)

     

     

     

  • 相关阅读:
    给大家分享两款正在使用的reflector插件
    Win32汇编项目总结——猎杀潜航
    SQL Server2008 数据库误删除数据的恢复方法分享
    DataGridView中使DataGridViewComboBox可编辑
    将SQL数据库还原到某个时间点
    SQL Server 2005对海量数据处理
    SQL Server 2005对海量数据处理(1)
    ILDASM的使用
    QT简介以及配置
    Reflector插件介绍
  • 原文地址:https://www.cnblogs.com/rsapaper/p/8179496.html
Copyright © 2011-2022 走看看