nodejs作业服务器(多用途) [英] nodejs job server (multiple purpose)

查看:49
本文介绍了nodejs作业服务器(多用途)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,只是结识了node.js(作为PHP开发人员的背景).我已经在nodejs网站上看到了一些nodeJs示例和视频.

I'm fairly new and just getting to know node.js (background as PHP developer). I've seen some nodeJs examples and the video on nodejs website.

当前,我正在运行一个视频网站,并且在后台必须执行许多任务.目前,这是由调用php脚本的cronjobs完成的.这种方法的缺点是,当另一个进程仍在运行时,如果启动另一个进程,则服务器等上的负载会很大.

Currently I'm running a video site and in the background a lot of tasks have to be executed. Currently this is done by cronjobs that call php scripts. The downsite of this approach is when an other process is started when the previous is still working you get a high load on the servers etc.

需要在服务器上完成的作业如下:

The jobs that needs to be done on the server are the following:

  • 抓取网站中的供稿并将其插入mysql数据库中
  • 从网站获取数据(抓取)(应要求提供)
  • 生成数据以进行报告.这些大多是需要执行的mysql查询.

将来需要完成的任务

  • 记录视频观看次数(当用户访问视频页面时)(这也将记录到mysql)
  • 一般记录访客
  • 根据搜索到的视频显示广告

我希望能够调用url,以便可以将作业排队,还可以按时间计划作业,或者它们可以连续运行.

I want to be able to call an url so that a job can be queued and also be able to schedule jobs by time or they can run constantly.

我不知道node.js是否是遵循的路径,这就是为什么我在这里问它.在节点中执行此操作有什么优势?场外?

I don't know if node.js is the path to follow that's why I'm asking it here. What are the advantages of doing this in node? The downsites?

node.js的专业人士在哪里?

What are the pro's here with node.js?

感谢您的回复!

推荐答案

传统上用于Web/网络任务(Web服务器,IRC聊天服务器等)的Node.js在为您提供任何类型的IO绑定时都会发光(与CPU绑定相反)任务,因为它使用完全异步的IO(也就是说,所有IO都发生在主事件循环之外).例如,Node可以轻松地保持打开的多个套接字,等待每个套接字上的数据,或者非常高效地将数据与文件进行流传输.

While traditionally used for web/network tasks (web servers, IRC chat servers, etc.), Node.js shines when you give it any kind of IO bound (as opposed to CPU bound) task, since it uses completely asynchronous IO (that is, all IO happens outside of the main event loop). For example, Node can easily hold open many sockets, waiting for data on each, or stream data to and from files very efficiently.

听起来好像您只是在寻找作业队列;流行的是 Resque ,尽管它是为Ruby编写的,但也有

It really sounds like you're just looking for a job queue; a popular one is Resque, and though it's written for Ruby, there are versions for PHP, Node.js, and more. There are also job queues built specifically for PHP; if you want to stick to PHP, a Google search for "PHP job queue" make take you far.

现在,再次使用Node.js的一个优点是,它非常容易处理大量IO的能力.当然,我只是在猜测,但是根据您的要求,它可能是完成这项工作的好工具:

Now, one advantage to using Node.js is, again, its ability to handle a lot of IO very easily. Of course I'm just guessing, but based on your requirements, it could be a good tool for the job:

  • Scrape data/feeds from websites - mostly waiting on network IO
  • Insert data into MySQL - mostly waiting on network IO
  • Reporting - again, Node is good at MySQL queries, but probably not so good at analyzing data
  • Call a URL to schedule a job - Node's built-in HTTP handling and excellent web libraries make this a cinch

因此,您完全有可能要尝试使用Node来完成这些任务.如果您这样做,请查看Resque for Node或其他作业系统,例如 Kue .如果您不需要复杂的东西,构建自己的东西也不是很难- Redis是一个很好的工具.

So it's entirely possible you may want to experiment with Node for these tasks. If you do, take a look at Resque for Node or another job system like Kue. It's also not very hard to build your own, if you don't need something complicated--Redis is a good tool for this.

出于某些原因,您可能想要使用Node.如果您不熟悉JavaScript和已发布

There are a few reasons you might not want to use Node. If you're not familiar with JavaScript and evented and continuation-passing style programming, Node.js may have a bit of a learning curve, as you have to force yourself to stop thinking synchronously. Furthermore, if you do have a lot of heavy non-IO tasks in your program, such as analyzing data, Node will not excel as those calculations will block the main event loop and keep Node from handling callbacks, etc. for your asynchronous IO. Finally, if you have a lot of logic already in PHP or another language, it may be easier and/or quicker to find a solution in your language of choice.

这篇关于nodejs作业服务器(多用途)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆