Skip to content

Commit 7605ed9

Browse files
committed
📌 Nodepp | Better Error Handling | V1.4.1 📌
1 parent fe3ed89 commit 7605ed9

38 files changed

Lines changed: 1354 additions & 973 deletions

README.md

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
[![Build Status](https://github.com/NodeppOfficial/nodepp/actions/workflows/main.yml/badge.svg)](https://github.com/NodeppOfficial/nodepp/actions)
66
[![Valgrind Memory Test](https://img.shields.io/badge/memory-zero_leaks-green)](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/valgrind_benchmark/readme.md)
77

8+
Nodepp is the end of excuses. For too long, developers have settled for **fragmented glue-ware** or managed runtimes that treat hardware resources like garbage. Nodepp is a vertically-integrated C++ framework that proves you don't need a massive Virtual Machine or a bloated Garbage Collector to write high-level async code.
89

9-
**Nodepp** is a vertically integrated C++ runtime engineered to eliminate the Hardware Tax in cloud and edge computing. It bridges the gap between high-level developer velocity and low-level mechanical sympathy.
10+
While others are busy **masturbating the CPU** — burning millions of cycles on garbage collection, context switching, and runtime management — Nodepp focuses on Pure Execution. It provides a unified world architecture where every module shares the same high-efficiency DNA, scaling from an 8-bit Arduino to an Intel XEON cloud server.
1011

1112
```
1213
NODEPP UNIFIED ARCHITECTURE: Co-designed components MODEL
@@ -32,15 +33,23 @@ NODEPP UNIFIED ARCHITECTURE: Co-designed components MODEL
3233

3334
## 📃 Whitepaper
3435

35-
[Scaling the Talent Bridge for Green Computing: Achieving Silicon-Logic Parity through Deterministic RAII](https://nodeppofficial.github.io/nodepp-doc/whitepaper) Read the full technical breakdown, including architectural deep-dives into `ptr_t`, `kernel_t` and `coroutine_t`.
36+
[Nodepp: Closing the Gap Between Bare-Metal Performance and Scripting Agility through Silicon-Logic Parity](https://nodeppofficial.github.io/nodepp-doc/whitepaper) Read the full technical breakdown, including architectural deep-dives into `ptr_t`, `kernel_t` and `coroutine_t`.
3637

37-
## 🌿 Sustainability & Performance (Green Computing)
38+
## ⭐ Architectural Philosophy
39+
40+
- **📌: 1. Deterministic RAII (`ptr_t`):** Eliminates the unpredictable latency spikes (Stop-the-World) of Garbage Collectors. By utilizing Small Stack Optimization (SSO) and reference counting, memory is reclaimed with microsecond precision.
41+
42+
- **📌: 2. Cooperative Multitasking (`coroutine_t`):** Stackless coroutines eliminate context-switching overhead. This allows for massive connection density on low-power hardware, from 8-bit industrial sensors to cloud-scale reactors.
43+
44+
- **📌: 3. Platform-Agnostic Reactor (`kernel_t`):** A unified abstraction over native kernel I/O `(Epoll, Kqueue, IOCP, and Npoll)`. It provides a consistent non-blocking interface across Linux, Windows, Mac, and Bare-Metal, ensuring that I/O multiplexing is always native to the silicon.
3845

39-
In the post-Moore's Law era, hardware is no longer infinitely cheap. Traditional managed runtimes (Node.js, Go, Java) prioritize abstractions that create a 11,000x Virtual Memory Gap. Nodepp reclaims this efficiency, enabling Resource-Dense Computing where a single node does the work of an entire cluster.
46+
## 🖕 Technical Reality Check: Data vs. Hype
4047

41-
### 📈 Performance Benchmark: HTTP Throughput vs. Resource Tax
48+
We didn't test this on a supercomputer. We tested it on an educational-grade Dual-Core Apollo Lake potato. If your framework can't perform here, it's not "scalable" — it's just hiding behind hardware.
4249

43-
> **Test:** 100k requests | 1k Concurrency | Environment: Localhost | Device: Educational-grade Dual-Core Apollo lake Chromebook [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/server_benchmark/readme.md)
50+
**1 - Performance Benchmark: HTTP Throughput vs. Resource Tax**
51+
52+
> **Test:** 100k requests | 1k Concurrency | Environment: Localhost [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/server_benchmark/readme.md)
4453
4554
| Metric | Bun (v1.3.5) | Go (v1.18.1) | Nodepp (V1.4.0) | Impact |
4655
| --- | --- | --- | --- | --- |
@@ -50,21 +59,21 @@ In the post-Moore's Law era, hardware is no longer infinitely cheap. Traditional
5059
| p99 Latency | 1,159 ms | 249 ms | 187 ms | High-precision SLA stability |
5160
| Energy Efficiency | Low | Medium | Extreme | Maximum hardware utilization |
5261

53-
### 📈 Performace Benchmark: Resource Management & Latency Jitter Analysis
62+
**2 - Performace Benchmark: Resource Management & Latency Jitter Analysis**
5463

55-
> **Test:** 1k Cycles | 100k Allocations | Environment: Educational-grade Dual-Core Apollo lake Chromebook [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/gc_benchmark/readme.md)
64+
> **Test:** 1k Cycles | 100k Allocations [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/gc_benchmark/readme.md)
5665
5766
| Runtime | Avg. Cycle Time | VIRT (Address Space) | RES (Physical RAM) | Memory Model |
5867
| --- | --- | --- | --- | --- |
5968
| Nodepp | 3.0 ms (±0.1 ms) | 6.1 MB | 2.7 MB | Deterministic RAII |
6069
| Bun | 7.2 ms (5-11 ms range) | 69.3 GB | 72.6 MB | Generational GC |
6170
| Go | < 1.0 ms* | 703.1 MB | 2.2 MB | Concurrent GC |
6271

63-
> **Note:** Go's <1ms measurement reflects allocation latency only; reclamation is deferred to concurrent garbage collection cycles.
72+
> **Note:** Go's <1ms measurement is a lie — it only reflects allocation latency. Reclamation is deferred to concurrent GC cycles, creating "ghost" resource pressure.
6473
65-
### 📈 Performace Benchmark: High-Concurrency Benchmark - 100k Task Challenge
74+
**3 - Performace Benchmark: High-Concurrency Benchmark - 100k Task Challenge**
6675

67-
> **Test:** 100k asynchronous tasks | Environment: Educational-grade Dual-Core Apollo lake Chromebook [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/task_benchmark/readme.md)
76+
> **Test:** 100k asynchronous tasks [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/task_benchmark/readme.md)
6877
6978
| Runtime | RSS (Memory) | CPU Load | VIRT Memory | Strategy |
7079
| --- | --- | --- | --- | --- |
@@ -73,9 +82,9 @@ Nodepp (Single) | 59.0 MB | 59.9% | 62 MB | Single Event Loop |
7382
Bun | 64.2 MB | 24.2% | 69.3 GB | JavaScriptCore Loop |
7483
Go | 127.9 MB | 169.4% | 772 MB | Preemptive Goroutines |
7584

76-
### 📈 Performace Benchmark: Nodepp Stability & Memory Benchmarks
85+
**4 - Performace Benchmark: Nodepp Stability & Memory Benchmarks**
7786

78-
> **Test:** 4 Valgrind-based stress tests | Environment: Educational-grade Dual-Core Apollo lake Chromebook [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/valgrind_benchmark/readme.md)
87+
> **Test:** 4 Valgrind-based stress tests [see benchmark](https://github.com/NodeppOfficial/nodepp/blob/main/benchmark/valgrind_benchmark/readme.md)
7988
8089
| Test Case | Objective | Iterations / Load | Memory Leaks | Result |
8190
| --- | --- | --- | --- | --- |
@@ -84,13 +93,52 @@ Go | 127.9 MB | 169.4% | 772 MB | Preemptive Goroutines |
8493
| Broken Pipe | Resilience to I/O failure | 100k interruptions | 0 bytes | PASSED |
8594
| Multi-Thread Atomicity | race conditions stress | 100k Messages * 2 workers | 0 bytes | PASSED |
8695

87-
## ⭐ Architectural Philosophy
96+
## 🚀 Why Nodepp Exists
8897

89-
- **📌: 1. Deterministic RAII (`ptr_t`):** Eliminates the unpredictable latency spikes (Stop-the-World) of Garbage Collectors. By utilizing Small Stack Optimization (SSO) and reference counting, memory is reclaimed with microsecond precision.
98+
The Nodepp Project did not originate in a laboratory; it was forged in the trenches of mission-critical Edge Computing and WASM development. While architecting ecosystems that bridge ESP32 hardware, web browsers, and cloud infrastructure, we identified a systemic crisis: the forced fragmentation of a single business logic across three incompatible execution environments.
9099

91-
- **📌: 2. Cooperative Multitasking (`coroutine_t`):** Stackless coroutines eliminate context-switching overhead. This allows for massive connection density on low-power hardware, from 8-bit industrial sensors to cloud-scale reactors.
100+
- **The Edge:** Native C/C++ for low-level hardware (High performance, near-zero agility).
101+
- **The Frontend:** JavaScript/WASM for browser interfaces (High agility, massive memory churn).
102+
- **The Infrastructure:** Managed Runtimes like Python, Go, or Node.js for server-side orchestration (High operational cost, unpredictable latency due to Garbage Collection).
103+
104+
Nodepp was built to collapse these silos. By providing a unified, asynchronous C++ runtime that mirrors the productivity of scripting languages, we enable Resource-Dense Computing.
105+
106+
```cpp
107+
#include <nodepp/nodepp.h>
108+
#include <nodepp/http.h>
109+
110+
using namespace nodepp;
111+
112+
void onMain() {
113+
114+
fetch_t args;
115+
args.method = "GET";
116+
args.url = "http://ip-api.com/json/?fields";
117+
args.headers = header_t({
118+
{ "Host", url::host(args.url) }
119+
});
120+
121+
http::fetch( args )
122+
123+
.then([]( http_t cli ){
124+
auto data = stream::await( cli );
125+
console::log("->", data.value());
126+
})
127+
128+
.fail([]( except_t err ){
129+
console::error( err );
130+
});
131+
132+
}
133+
```
134+
135+
We restore the direct relationship between code and hardware through Deterministic RAII and Stackless Coroutines, allowing you to deploy the same high-level logic from an 8-bit microcontroller to a 64-core cloud reactor without changing your mental model.
136+
137+
**Still Skeptical?**
138+
139+
Watch logic-parity in action. This isn't a "concept"—it's [ A Fully Functional Enigma Machine running in a Literal Potato board ](https://wokwi.com/projects/449104127751150593):
92140

93-
- **📌: 3. Platform-Agnostic Reactor (`kernel_t`):** A unified abstraction over native kernel I/O (Epoll, Kqueue, IOCP, and Npoll). It provides a consistent non-blocking interface across Linux, Windows, Mac, and Bare-Metal, ensuring that I/O multiplexing is always native to the silicon.
141+
https://github.com/user-attachments/assets/9b870671-3854-444f-893d-40fdce31a629
94142

95143
## 🧭 Quick Start: High-Density HTTP
96144
Nodepp abstracts complex socket management into a clean, event-driven API.
@@ -145,7 +193,8 @@ Nodepp is the only framework that lets you share logic between the deepest embed
145193
- **📌: Hardware:** [NodePP for Arduino](https://github.com/NodeppOfficial/nodepp-arduino)
146194
- **📌: Desktop:** [Nodepp for Desktop](https://github.com/NodeppOfficial/nodepp)
147195
- **📌: Browser:** [Nodepp for WASM](https://github.com/NodeppOfficial/nodepp-wasm)
148-
- **📌: IOT:** [ Nodepp for ESP32 ](https://github.com/NodeppOfficial/nodepp-esp32)
196+
- **📌: ESP32:** [Nodepp for ESP32](https://github.com/NodeppOfficial/nodepp-esp32)
197+
- **📌: EPS8266:** [Nodepp for ESP8266](https://github.com/NodeppOfficial/nodepp-esp8266)
149198

150199
## ❤️‍🩹 Contributing
151200

examples/35-Connect-to-API.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void onMain(){
2323
}
2424

2525
auto raw = stream::await( cli );
26-
auto obj = json::parse( raw );
26+
auto obj = json::parse ( raw.value() );
2727

2828
console::log( "country:", obj["country"].as<string_t>() );
2929
console::log( "city:" , obj["city"] .as<string_t>() );

examples/39-LoadBalancing.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ using namespace nodepp;
1212
void server( int process ){
1313

1414
auto server = http::server([=]( http_t cli ){
15+
16+
console::log( ">>", cli.path );
1517

1618
cli.write_header( 200, header_t({
1719
{ "Content-Type", "text/html" }
@@ -32,9 +34,15 @@ void onMain(){
3234

3335
if ( process::is_child() ){ server( os::pid() ); } else {
3436
for( auto x = os::cpus(); x--; ){
35-
cluster::add().onData([=]( string_t data ){
37+
38+
auto pid = cluster::add();
39+
40+
if ( !pid.has_value() ){ throw except_t( "something went wrong" ); }
41+
42+
pid.value().onData([=]( string_t data ){
3643
conio::log( data );
3744
});
45+
3846
}}
3947

4048
}

examples/40-Cluster.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ using namespace nodepp;
77
void onMain() {
88

99
if( process::is_parent() ){
10+
1011
auto pid = cluster::add();
1112

12-
pid.onDrain([=](){ console::log("Done"); });
13-
pid.onData([=]( string_t data ){
13+
if( !pid.has_value() ){ throw except_t( "something went wrong" ); }
14+
15+
pid.value().onDrain([=](){ console::log("Done"); });
16+
pid.value().onData ([=]( string_t data ){
1417
console::log("->",data);
1518
});
1619

1720
} else {
21+
1822
process::add( coroutine::add( COROUTINE(){
1923
static uint x = 10;
2024
coBegin

examples/40-Popen.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ using namespace nodepp;
55

66
void onMain(){
77

8-
auto pid = popen::async( "curl https://www.google.com -Ls" );
8+
auto pid = popen::add( "curl https://www.google.com -Ls" );
99

10-
pid.onData([]( string_t data ){ console::log( data ); });
11-
pid.onClose([=](){ console::log("done"); });
10+
if( !pid.has_value() ){
11+
throw except_t( "something went wrong" );
12+
}
13+
14+
pid.value().onData([]( string_t data ){
15+
console::log( data );
16+
});
17+
18+
pid.value().onClose([=](){
19+
console::log("done");
20+
});
1221

1322
}

include/nodepp/cluster.h

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,69 +15,99 @@
1515
/*────────────────────────────────────────────────────────────────────────────*/
1616

1717
#if _KERNEL_ == NODEPP_KERNEL_WINDOWS
18+
#define PWROUTINE( str, cb ) worker::add( cb )
19+
#define PWDELAY( TIMEOUT ) worker::delay( TIMEOUT )
1820

1921
#include "fs.h"
2022
#include "worker.h"
23+
#include "promise.h"
2124
#include "initializer.h"
2225
#include "windows/cluster.h"
2326

24-
namespace nodepp { namespace cluster {
27+
#elif _KERNEL_ == NODEPP_KERNEL_POSIX
28+
#define PWROUTINE( str, cb ) process::poll( str, POLL_STATE::READ | POLL_STATE::EDGE, cb )
29+
#define PWDELAY( TIMEOUT )
2530

26-
template< class... T > cluster_t async( const T&... args ){
27-
auto pid = type::bind( cluster_t(args...) );
28-
if( process::is_parent() ) {
29-
worker::add([=](){ return pid->next(); });
30-
} return *pid; }
31+
#include "fs.h"
32+
#include "promise.h"
33+
#include "initializer.h"
34+
#include "posix/cluster.h"
3135

32-
template< class... T > cluster_t add( const T&... args ){
33-
return async( args... ); }
36+
#else
37+
#error "This OS Does not support cluster.h"
38+
#endif
3439

35-
template< class... T > int await( const T&... args ){
36-
auto pid = type::bind( cluster_t(args...) );
37-
if( process::is_parent() ) {
38-
return worker::await([=](){ return pid->next(); });
39-
} return -1; }
40+
/*────────────────────────────────────────────────────────────────────────────*/
4041

41-
inline bool is_child(){ return !process::env::get("CHILD").empty(); }
42+
namespace nodepp { namespace cluster {
4243

43-
inline bool is_parent(){ return process::env::get("CHILD").empty(); }
44+
inline bool is_child(){ return !process::env::get("CHILD").empty(); }
4445

45-
}}
46+
inline bool is_parent(){ return process::env::get("CHILD").empty(); }
4647

48+
/*─······································································─*/
4749

48-
#elif _KERNEL_ == NODEPP_KERNEL_POSIX
50+
template< class... T >
51+
expected_t<cluster_t,except_t> add( const T&... args ){ try {
4952

50-
#include "fs.h"
51-
#include "initializer.h"
52-
#include "posix/cluster.h"
53+
auto rd1 = type::bind( generator::file::read() );
54+
auto rd2 = type::bind( generator::file::read() );
55+
auto pid = type::bind( cluster_t( args... ) );
5356

54-
namespace nodepp { namespace cluster {
57+
PWROUTINE( pid->readable(), coroutine::add( COROUTINE(){
58+
coBegin
5559

56-
template< class... T > cluster_t async( const T&... args ){
57-
auto pid = type::bind( cluster_t(args...) );
58-
if( process::is_parent() ) {
59-
process::add([=](){ return pid->next(); });
60-
} return *pid; }
60+
if( (*rd1)( &pid->readable() )==1 ) { coGoto(0); }
61+
if( rd1->state==0 )/**/{ pid->free(); coEnd; }
62+
pid->onDout.emit( rd1->data );
63+
pid->onData.emit( rd1->data );
6164

62-
template< class... T > cluster_t add( const T&... args ){
63-
return async( args... ); }
65+
PWDELAY( 100 );
66+
coGoto(0); coFinish; }));
6467

65-
template< class... T > int await( const T&... args ){
66-
auto pid = type::bind( cluster_t(args...) );
67-
if( process::is_parent() ) {
68-
return process::await([=](){ return pid->next(); });
69-
} return -1; }
68+
if( is_child() ){ return *pid; }
69+
70+
PWROUTINE( pid->std_error(), coroutine::add( COROUTINE(){
71+
coBegin
7072

71-
inline bool is_child(){ return !process::env::get("CHILD").empty(); }
73+
if( (*rd2)( &pid->std_error() )==1 ){ coGoto(0); }
74+
if( rd2->state==0 )/**/{ pid->free(); coEnd; }
75+
pid->onDerr.emit( rd2->data );
76+
pid->onData.emit( rd2->data );
7277

73-
inline bool is_parent(){ return process::env::get("CHILD").empty(); }
78+
PWDELAY( 100 );
79+
coGoto(0); coFinish; }));
7480

75-
}}
81+
return *pid;
82+
83+
} catch( except_t err ) { return err; } }
7684

77-
#else
78-
#error "This OS Does not support cluster.h"
79-
#endif
85+
/*─······································································─*/
86+
87+
template< class... T >
88+
promise_t<string_t,except_t> resolve( const T&... args ){
89+
return promise_t<string_t,except_t>([=](
90+
res_t<string_t> res, rej_t<except_t> rej
91+
){
92+
93+
auto pid = cluster::add( args... );
94+
auto bff = ptr_t<string_t>( 0UL );
95+
96+
if( !pid.has_value() ){ rej( pid.error() ); }
97+
98+
pid.value().onDrain([=](){ res( *bff ); });
99+
pid.value().onData([=]( string_t chunk ){
100+
*bff += chunk;
101+
});
102+
103+
}); }
104+
105+
}}
80106

81107
/*────────────────────────────────────────────────────────────────────────────*/
82108

83-
#endif
109+
#undef PWROUTINE
110+
#undef PWDELAY
111+
#endif
112+
113+
/*────────────────────────────────────────────────────────────────────────────*/

include/nodepp/coroutine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace nodepp { namespace coroutine {
9595
case 0: tmp.flag=STATE::CO_STATE_BLOCK; break;
9696
case 1: tmp.flag=STATE::CO_STATE_YIELD; break;
9797
default: tmp.flag=STATE::CO_STATE_START; break;
98-
}
98+
}
9999

100100
DONE:; return out; }
101101
}}

0 commit comments

Comments
 (0)