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)

     

     

     

  • 相关阅读:
    时间差的计算
    时间差的计算第二篇
    并不能完全不编码完成Windows Service的安装和卸载
    今年是搜索引擎年吗?热!搜索引擎算法点击率火爆
    Virtual PC,我真的不敢用你!
    我理解的17种C#写的Hello World程序
    反搜索引擎
    如何保证Windows Serverice健壮长效运转?
    服务器是怎么做成的?
    超酷的超级DataGrid
  • 原文地址:https://www.cnblogs.com/rsapaper/p/8179496.html
Copyright © 2011-2022 走看看