热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

node.js中的节点到底是什么?-Whatexactlyisanodeinnode.js?

InErlangIwasabletoimmediatelyunderstandthenotionofanode-aself-containedErlangVM.

In Erlang I was able to immediately understand the notion of a 'node' - a self-contained Erlang VM. I could start a node on one machine with erl -name gandalf -setCOOKIE abc, and another node on another machine (on the same LAN) with erl -name bilbo -setCOOKIE abc. I could then spawn processes on gandalf which would communicate magically with other processes on bilbo. Now, since I also wanted to serve up a jazzy webpage with animated graphical results from my Erlang processes, I picked up some Javascript and learnt jQuery. Still a humble paduwan, but I sort of understand how Javascript fits into the scheme of things.

在Erlang中,我能够立即理解“节点”的概念——一个自包含的Erlang VM。我可以在一台机器上用erl -name gandalf -setCOOKIE abc启动一个节点,在另一台机器上(在同一个局域网上)用erl -name bilbo -setCOOKIE abc启动另一个节点。然后,我可以在gandalf上生成进程,它将与bilbo上的其他进程通信。现在,由于我也想用Erlang过程生成的动画图形结果创建一个花哨的网页,所以我学习了一些Javascript并学习了jQuery。仍然是一个不起眼的paduwan,但是我有点理解Javascript是如何融入事物的计划的。

I recently came across node.js and an (evil) voice started whispering: 'This is it! Now you can do everything with Javascript! Forget Erlang and guards and periods, stick to a language that everyone uses'.

我最近遇到node。js和一个(邪恶的)声音开始窃窃私语:“就是这个!”现在你可以用Javascript做任何事情了!忘掉Erlang、警卫和句号,坚持大家都用的语言。

I've read the docs a bit, but I still don't understand what a node is in node.js. Do I have to run a http server and that becomes my node? What if I don't like http, or I don't care how gandalf talks to bilbo - that's what I like in Erlang. Maybe I nai:vely expect that node.js is erlang with Javascript sugar?

我已经读了一些文档,但是我仍然不理解node.js中的节点是什么。我是否必须运行一个http服务器,然后它就成为我的节点?如果我不喜欢http,或者我不在乎甘道夫怎么和比尔博说话——这就是我喜欢Erlang的地方。也许我奈:非常期待那个节点。js是erlang和Javascript糖吗?

4 个解决方案

#1


7  

Node.js has much more in common with Twisted than Erlang/OTP. Node.js is just a single threaded SEDA event loop. Node.js has nothing compared to Erlang VM when it comes to distribution, hot code reloading, and scalability via processes, it isn't anything close to "Erlang with Javascript sugar"

节点。js与Twisted比Erlang/OTP有更多的共同之处。节点。js只是一个单线程SEDA事件循环。节点。在分发、热代码重载和进程可扩展性等方面,js与Erlang虚拟机相比简直是小巫见大巫

#2


7  

Maybe because of your Erlang knowledge you thought that somehow Node.js had something to do with "nodes" (as erlang nodes), but it's just the name.

也许是因为你的Erlang知识,你认为这个节点。js与“节点”(如erlang节点)有关,但它只是名称。

The main idea with Node.js is that you defer all expensive I/O operations and assign callbacks to the result of those operations. The reason is that I/O blocks the (only) process that is running at the moment. Node.js will handle this for you, given that you are coding in the proper way.

节点的主要思想。js是延迟所有昂贵的I/O操作并为这些操作的结果分配回调。原因是I/O阻塞了当前正在运行的(惟一的)进程。节点。js将为您处理这个问题,因为您正在以正确的方式进行编码。

An easy example of this is a database call:

一个简单的例子是数据库调用:

result = SQL.query("EXPENSIVE SELECT HERE")
doSomething(result);
moreStuff(); // This line must wait until the previous ones are completed.

In node you would code this in a very different way:

在node,你可以用一种非常不同的方式来编码:

SQL.query("EXPENSIVE SELECT HERE", function(result) {
  doSomething(result);
});
moreStuff(); // This line executes inmediately

If you have wrong code in your Node.js script, like:

如果您的节点中有错误的代码。js脚本,如:

while(true) { }

Then you are blocking the process and it won't be able to handle more requests than the current one, so in Node.js is mandatory to follow the above guidelines.

然后阻塞进程,它将无法处理比当前请求更多的请求,因此在Node中。js必须遵守以上准则。

#3


4  

As I understand it, a Node.JS node is an instance of the V8 engine with the Node.JS runtime and event-loop running in it. While the Node.JS runtime gives you the ability to very quickly and simply begin processing HTTP requests, it's not mandatory; it is very good at handling most any kind of asynchronous I/O, really.

根据我的理解,是一个节点。JS节点是带有该节点的V8引擎的实例。JS运行时和事件循环在其中运行。而节点。JS运行时使您能够非常快速地开始处理HTTP请求,这不是强制性的;它非常擅长处理任何类型的异步I/O。

I don't know that much about Erlang, but my superficial understanding is that its great strength is high-concurrency computing. Node.JS doesn't specialize in that, per se. Its heart is "evented I/O", dealing neatly and cleanly with asynchronous I/O.

我不太了解Erlang,但我的表面理解是它的强大之处在于高并发计算。节点。JS本身并不擅长这个。它的核心是“唤醒I/O”,处理异步I/O时干净利落。

#4


1  

there is no "node" in node.js

node.js中没有“node”

as mentioned, when you run

如前所述,当您运行时

node my_script.js 

you are running one instance of V8 java script interpreter (which is using one core for its lifetime).

您正在运行一个V8 java脚本解释器实例(在其生命周期中使用一个核心)。


推荐阅读
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 本文介绍了C#中生成随机数的三种方法,并分析了其中存在的问题。首先介绍了使用Random类生成随机数的默认方法,但在高并发情况下可能会出现重复的情况。接着通过循环生成了一系列随机数,进一步突显了这个问题。文章指出,随机数生成在任何编程语言中都是必备的功能,但Random类生成的随机数并不可靠。最后,提出了需要寻找其他可靠的随机数生成方法的建议。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 本文介绍了机器学习手册中关于日期和时区操作的重要性以及其在实际应用中的作用。文章以一个故事为背景,描述了学童们面对老先生的教导时的反应,以及上官如在这个过程中的表现。同时,文章也提到了顾慎为对上官如的恨意以及他们之间的矛盾源于早年的结局。最后,文章强调了日期和时区操作在机器学习中的重要性,并指出了其在实际应用中的作用和意义。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
author-avatar
永欣慧娟766
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有