{"id":20743087,"url":"https://github.com/aimingoo/n4c","last_synced_at":"2025-07-28T07:10:26.208Z","repository":{"id":89039413,"uuid":"45819713","full_name":"aimingoo/n4c","owner":"aimingoo","description":"N4C is a Controllable \u0026 Computable Communication Cluster architecture.","archived":false,"fork":false,"pushed_at":"2016-03-14T08:12:09.000Z","size":36,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-05T21:35:51.065Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aimingoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-09T06:32:49.000Z","updated_at":"2024-03-09T05:06:33.000Z","dependencies_parsed_at":"2023-03-04T18:00:19.941Z","dependency_job_id":null,"html_url":"https://github.com/aimingoo/n4c","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aimingoo/n4c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2Fn4c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2Fn4c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2Fn4c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2Fn4c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aimingoo","download_url":"https://codeload.github.com/aimingoo/n4c/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aimingoo%2Fn4c/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267476454,"owners_count":24093515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T07:09:02.275Z","updated_at":"2025-07-28T07:10:26.180Z","avatar_url":"https://github.com/aimingoo.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"## N4C\n\nN4C是一个标准架构，它提供一套指导规范、案例和高度可靠的模块，用于在“可控、可计算、可通信的集群”上实现复杂的、稳定的业务逻辑。\n\n\u003e N4C is a Controllable \u0026 Computable Communication Cluster architecture.\n\nN4C最初提出的背景是面向实时计算的，它对实时计算提出了三点原则性意见，并作为N4C架构下的实时计算的基本原则。\n\n\u003e ``` \n\u003e - 没有全量：瞬态观察下，没有一致性与有效性的要求；在单次计算中的数据完整性是不必要的。\n\u003e - 就近计算：数据越早规格化则收益越高；总是存在数据合并的中心点，但可以是动态的；层次决定并行效率。\n\u003e - 精度逼近：不存在一次精确，应通过足够多的正确来逼近精确。\n\u003e ```\n\n实时计算并非N4C唯一考虑的环境因素。\n\n本项目(aimingoo/n4c)只提供N4C的标准化文档和相关的索引。\n\n### Table of Contents\n\n* [N4C specifications](#n4c-specifications)\n  * [1. N4C architecture](#1-n4c-architecture)\n  * [2. PEDT specifications](#2-pedt-specifications)\n* [N4C projects](#n4c-projects)\n  * [PEDT implements](#pedt-implements)\n    * [redpoll](#redpoll)\n    * [harpseal](#harpseal)\n    * [tundrawolf](#tundrawolf)\n    * [pedt-scala](#pedt-for-scala)\n  * [N4C implements](#n4c-implements)\n    * [ngx_4c](#ngx_4c)\n    * [sandpiper](#sandpiper)\n* [N4C documents](#n4c-documents)\n* [others](#others)\n* [history](#history)\n\n# N4C specifications\n\n## 1. N4C architecture\n\n![n4c architecture](https://github.com/aimingoo/n4c/wiki/images/n4c_architecture.png)\n\nN4C整体是一个并行的分布式计算架构，包括如下特性：\n\n- 实时性：支持就地计算以提供足够的实时性\n- 分布式：使用PEDT分布式任务规范\n- 并行计算：Promise并行计算模型\n\n集群构建在N4C中被称为可通信集群（Communication Cluster），它要求集群的各节点间可以成组通信，这种“成组”的关系被抽象为资源描述（n4c resource description），并通过接口(n4c resource interface)反映到资源管理层。\n\n任务管理层是一个抽象层，其底层的资源管理被再次抽象为范围（Scope）。被放在最顶的应用层不再直接面对“资源”，从而避免了“资源调度”这样的问题。应用层已经被特定地描述为一种“分布式任务”，并有一个独立的规范定义，称为PEDT（Parallel Exchangeable Distribution Task）。\n\nPEDT定义了任务的格式、交互的方法，以及最重要的是，它也定义了“任务调度”的基本单元与模式。\n\n## 2. PEDT specifications\n\n\u003e @see $(n4c)/PEDT/*\n\n并行的可交换分布式任务（PEDT, Parallel Exchangeable Distribution Task）是以可计算集群为对象的、以实时处理为目标的并行任务规范。该规范包括对任务数据、任务处理和任务调用接口三个部分的定义。\n\nPEDT旨在为可计算集群提供一种轻量、高效和跨平台的可靠任务处理机制。\n\n# N4C projects\n\n本节列出有关N4C的主要开源项目。\n\n## PEDT implements\n\n* [redpoll for nodejs](https://github.com/aimingoo/redpoll)\n* [harpseal for lua](https://github.com/aimingoo/harpseal)\n* [tundrawolf for nginx_lua](https://github.com/aimingoo/tundrawolf)\n* [pedt-scala](https://github.com/cyber4ron/pedt-scala)\n\n### redpoll\n\nredpoll（红顶雀）是一个nodejs上的项目，它完整地实现了PEDT 1.1。它可以作为一个npm的模块安装。\n\n[https://github.com/aimingoo/redpoll](https://github.com/aimingoo/redpoll)\n\n### harpseal\n\nharpseal（竖琴海豹）是一个lua上的项目，它在原生lua上实现了PEDT 1.1。它需要LuaScoket模块来实现http client，并且需要copas模块来实现并行的http requests。\n\n\u003e [https://github.com/aimingoo/harpseal](https://github.com/aimingoo/harpseal)\n\nharpseal实现了一个完整的distributionScope解析函数(prefixParse in infra/taskhelper.lua)，这是最符合PEDT规范的三段标记(three parts token)解析算法。这与其它（例如redpoll for nodejs）很不相同，他们（后者）通常采用简单的前缀匹配来处理三段标记。参见：\n\n\u003e ``` text\n\u003e $(harpseal)/testcase/t_pedt_prefix.lua\n\u003e ```\n\nharpseal还实现了一个递归注册taskDef的工具，可以将多层次的taskDef一次性地注册到register_center，参见：\n\n\u003e ``` text\n\u003e $(harpseal)/testcase/t_loadTask.lua\n\u003e $(harpseal)/tools/taskloader.lua\n\u003e ```\n\n### tundrawolf\n\ntundrawolf（冻原狼）是一个nginx_lua上的项目，它与harpseal（竖琴海豹）项目是基本相同的，但直接使用nginx lua中内置的http client、MD5、BASE64等功能/模块，是专门为nginx lua环境定制的。\n\n\u003e [https://github.com/aimingoo/tundrawolf](https://github.com/aimingoo/tundrawolf)\n\ntundrawolf实现了一种独特的（独立的）机制：路由发现（system_route discoveries）。用于管理当前结点中注册到系统路由(system_route)的对象。这些对象可以是任何（除lua false/nil值之外的）东西。一旦这些对象注册到系统路由，那么它就可以在Promise框架中作为并行对象来使用了。\n\ntundrawolf通常是在nginx lua中实现N4C的基础组件。\n\n### PEDT for Scala\n\nPEDT-scala是一个在scala上，基于Nashorn Javascript实现的PEDT协议。采用了scala来实现PEDT协议本身（其\"com.wandoujia.n4c.pedt.core.PEDT4JS\"是一个原生的java对象），并使用javascript来交付可扩展的可编程接口。\n\n\u003e [https://github.com/cyber4ron/pedt-scala](https://github.com/cyber4ron/pedt-scala)\n\nPEDT-scala实现了一个简单的、测试用的n4c mock，部分第三方项目可以参考该mock来完成PEDT协议的测试（另外，也可以选用Sandpiper in nodejs来作为测试用的资源服务器）。\n\nPEDT-scala描述了一个清晰而简洁的工作框架。\n\n![illustrate pedt-scala](https://github.com/cyber4ron/notes/raw/master/images/pedt-scala.png)\n\n## N4C implements\n\n* [ngx_4c in nginx](https://github.com/aimingoo/ngx_4c)\n* [sandpiper in nodejs](https://github.com/aimingoo/sandpiper)\n\n### ngx_4c\n\nngx_4c是一个在nginx上的编程框架，它基于如下项目来实现了N4C架构：\n\n\u003e * tundrawolf\n\u003e   \n\u003e   实现PEDT distribution tasks规范。\n\u003e   \n\u003e * ngx_cc\n\u003e   \n\u003e   实现nginx集群内通信。\n\u003e   \n\u003e * Promise\n\u003e   \n\u003e   实现并行处理。\n\u003e   \n\u003e * Events\n\u003e   \n\u003e   实现了在nginx下实现的，基于多投事件的标准编程架构；并基于Events实现了N4C中的资源管理和任务管理服务。\n\u003e   \n\u003e * etcd\n\u003e   \n\u003e   使用etcd来做N4C中集群构建层的存储和心跳通知。\n\n你需要安装一个nginx来构建你的测试环境。由于ngx_4c可选集成ngx_cc，而后者需要在nginx上打一个特定的补丁以便为每个nginx工作进程分配一个通信端口，因此建议你先参考如下文档：\n\n\u003e ``` text\n\u003e https://github.com/aimingoo/ngx_4c#install--usage\n\u003e ```\n\n但是，如果不集成ngx_cc，那么ngx_4c本身并不要求nginx打上述补丁。\n\n### sandpiper\n\nsandpiper（Baird's sandpiper, 黑腰滨鹬）是一个在nodejs上的N4C实现，它基于如下项目：\n\n\u003e * redpoll\n\u003e   \n\u003e   实现PEDT distribution tasks规范。\n\u003e   \n\u003e * node-etcd-promise\n\u003e   \n\u003e   使用promise并行处理实现的etcd客户端。\n\u003e   \n\u003e * request\n\u003e   \n\u003e   简单的http客户端。\n\u003e   \n\u003e * crc-32\n\u003e   \n\u003e   在注册任务时使用crc-32对taskDef进行二次验证。\n\u003e   \n\u003e * etcd\n\u003e   \n\u003e   使用etcd来做N4C中集群构建层的存储和心跳通知。\n\nsandpiper使用nodejs内建的标准Promise来实现并行处理。与ngx_4c类似，它实现了完整的资源中心与任务中心，并发布了它们的标准客户端界面。基于PEDT规范，它完整地实现了N4C集群中执行者(exeutor)、发布者(publisher)、分发者(dispatcher)等角色。\n\nsandpiper提供一些小工具，包括一个资源服务（用于快速地检测/测试其它的N4C项目）：\n\n``` bash\n\u003e git clone 'http://github.com/aimingoo/sandpiper'\n\u003e npm install; npm start\n```\n\n# N4C documents\n\n本节列出有关N4C的主要一些公开文档或讨论。\n\n# others\n\n其它未确定内容。\n\n\n\n# history\n\n``` text\n\t2015.11\t\tN4C opensource and github hosted.\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faimingoo%2Fn4c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faimingoo%2Fn4c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faimingoo%2Fn4c/lists"}