@avalw/search-worker 1.1.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,303 +1,303 @@
1
1
  # @avalw/search-worker
2
2
 
3
- Free privacy-focused search API in exchange for compute power.
3
+ ```
4
+ ___ _ _____ _ __ __
5
+ / | | / / | | / / / /
6
+ / /| | | / / /| | |/ / _ __/ /_
7
+ / ___ | |/ / ___ | / | '__ __|
8
+ /_/ |_|___/_/ |_|_|\_\|_| |_|
4
9
 
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
- [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen)](https://nodejs.org)
10
+ Distributed Cache Worker v2.1.0
11
+ ```
7
12
 
8
- ## What is AVALW Worker?
13
+ Contribute your computer's cache storage to the AVALW search network and earn free API access in return.
9
14
 
10
- AVALW Worker is a lightweight Node.js application that runs on your server and contributes CPU power to the AVALW distributed network. In return, you get **free access** to the AVALW Search API - a privacy-focused search engine that doesn't track users. Your API quota scales with your contribution.
15
+ ## How It Works
11
16
 
12
- **No tracking. No ads. No data collection. Just search.**
17
+ ```
18
+ ┌─────────────────────────────────────────────────────────────────────────┐
19
+ │ AVALW DISTRIBUTED CACHE │
20
+ ├─────────────────────────────────────────────────────────────────────────┤
21
+ │ │
22
+ │ ┌─────────┐ ┌──────────────┐ ┌─────────────┐ │
23
+ │ │ User │────────▶│ avalw.org │────────▶│ Coordinator │ │
24
+ │ │ Search │ │ Server │ │ Server │ │
25
+ │ └─────────┘ └──────────────┘ └──────┬──────┘ │
26
+ │ │ │
27
+ │ ┌─────────────────────────┼───────┐ │
28
+ │ │ │ │ │
29
+ │ ▼ ▼ ▼ │
30
+ │ ┌──────────┐ ┌──────────┐ ┌──────┐ │
31
+ │ │ Worker 1 │ │ Worker 2 │ │ ... │ │
32
+ │ │ Cache │ │ Cache │ │ │ │
33
+ │ └──────────┘ └──────────┘ └──────┘ │
34
+ │ │
35
+ │ YOUR WORKER stores search results and serves them when requested │
36
+ │ │
37
+ └─────────────────────────────────────────────────────────────────────────┘
38
+ ```
13
39
 
14
- ## How It Works
40
+ ### The Flow
15
41
 
16
42
  ```
17
- ┌─────────────────────────────────────────────────────────────────────────────┐
18
- │ AVALW WORKER SYSTEM │
19
- ├─────────────────────────────────────────────────────────────────────────────┤
20
-
21
- YOUR SERVER AVALW NETWORK YOUR USERS
22
- ─────────── ──────────── ──────────
23
- │ │
24
- ┌─────────────┐ ┌─────────────┐ │
25
- │ │ Worker │ ───────────────►│ Compute
26
- │ │ Process │ Contributes │ Pool │ │
27
- │ │ │ Core-Hours │ │ │
28
- CPU: ████░ │ │ ┌─┐┌─┐┌─┐┌─┐│ │
29
- │ 70% │ │ └─┘└─┘└─┘└─┘│
30
- │ └─────────────┘ └──────┬──────┘ │
31
- │ │ │ │
32
- │ │ Reports: │ Calculates: │
33
- │ │ CPU cores │ Core-hours │
34
- │ │ • CPU speed (GHz) │ • Your tier │
35
- │ │ • Usage % │ • API quota │
36
- │ │ Online time │ │
37
- │ ▼ ▼ │
38
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
39
- │ Your App │◄────────────────│ Search API │◄───────│ Search │ │
40
- │ │ Free access │ (quota │ │ Query │ │
41
- │ // search │ based on │ based) │ │ │ │
42
- │ fetch(..); │ contribution │ │ │ "weather" │ │
43
- └─────────────┘ └─────────────┘ └─────────────┘ │
44
- │ │
45
- └─────────────────────────────────────────────────────────────────────────────┘
46
- ```
47
-
48
- ## Core-Hours System
49
-
50
- Unlike simple percentage-based systems, AVALW uses **Core-Hours** - a fair metric that accounts for your actual hardware contribution.
51
-
52
- ### What is a Core-Hour?
53
-
54
- ```
55
- ┌─────────────────────────────────────────────────────────────────────────────┐
56
- │ CORE-HOUR CALCULATION │
57
- ├─────────────────────────────────────────────────────────────────────────────┤
58
- │ │
59
- │ Core-Hours = CPU Cores × (CPU Speed ÷ 3.0 GHz) × Usage% × Hours Online │
60
- │ │
61
- │ ═══════════════════════════════════════════════════════════════════════ │
62
- │ │
63
- │ EXAMPLE: Intel i7-10700 running for 24 hours at 50% │
64
- │ │
65
- │ • Cores: 8 │
66
- │ • Speed: 2.9 GHz base (normalized to 3.0 GHz baseline) │
67
- │ • Usage: 50% │
68
- │ • Time: 24 hours │
69
- │ │
70
- │ Calculation: 8 × (2.9 ÷ 3.0) × 0.50 × 24 = 92.8 core-hours/day │
71
- │ │
72
- └─────────────────────────────────────────────────────────────────────────────┘
73
- ```
74
-
75
- ### Tiers Based on Core-Hours
76
-
77
- | Tier | Requests/Day | Core-Hours/Day | Minimum Cores |
78
- |------|--------------|----------------|---------------|
79
- | **Starter** | 1,000 | 3 | 3 cores |
80
- | **Basic** | 5,000 | 12 | 4 cores |
81
- | **Pro** | 20,000 | 36 | 6 cores |
82
- | **Business** | 50,000 | 72 | 8 cores |
83
- | **Enterprise** | 500,000 | 240 | 16 cores |
84
-
85
- ## Real CPU Examples
86
-
87
- ### Desktop CPUs
88
-
89
- ```
90
- ┌─────────────────────────────────────────────────────────────────────────────┐
91
- │ DESKTOP CPU EXAMPLES │
92
- ├─────────────────────────────────────────────────────────────────────────────┤
93
- │ │
94
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
95
- │ │ Intel Core i5-10400 (6 cores @ 2.9 GHz) │ │
96
- │ ├─────────────────────────────────────────────────────────────────────┤ │
97
- │ │ At 50% for 24h: 6 × 0.97 × 0.50 × 24 = 69.8 core-hours │ │
98
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
99
- │ │ │ │
100
- │ │ At 30% for 24h: 6 × 0.97 × 0.30 × 24 = 41.9 core-hours │ │
101
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
102
- │ └─────────────────────────────────────────────────────────────────────┘ │
103
- │ │
104
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
105
- │ │ Intel Core i7-10700 (8 cores @ 2.9 GHz) │ │
106
- │ ├─────────────────────────────────────────────────────────────────────┤ │
107
- │ │ At 50% for 24h: 8 × 0.97 × 0.50 × 24 = 93.1 core-hours │ │
108
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
109
- │ │ │ │
110
- │ │ At 25% for 24h: 8 × 0.97 × 0.25 × 24 = 46.6 core-hours │ │
111
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
112
- │ └─────────────────────────────────────────────────────────────────────┘ │
113
- │ │
114
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
115
- │ │ Intel Core i9-10900 (10 cores @ 2.8 GHz) │ │
116
- │ ├─────────────────────────────────────────────────────────────────────┤ │
117
- │ │ At 50% for 24h: 10 × 0.93 × 0.50 × 24 = 111.6 core-hours │ │
118
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
119
- │ │ │ │
120
- │ │ At 80% for 24h: 10 × 0.93 × 0.80 × 24 = 178.6 core-hours │ │
121
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
122
- │ └─────────────────────────────────────────────────────────────────────┘ │
123
- │ │
124
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
125
- │ │ AMD Ryzen 5 5600X (6 cores @ 3.7 GHz) │ │
126
- │ ├─────────────────────────────────────────────────────────────────────┤ │
127
- │ │ At 50% for 24h: 6 × 1.23 × 0.50 × 24 = 88.6 core-hours │ │
128
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
129
- │ └─────────────────────────────────────────────────────────────────────┘ │
130
- │ │
131
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
132
- │ │ AMD Ryzen 7 5800X (8 cores @ 3.8 GHz) │ │
133
- │ ├─────────────────────────────────────────────────────────────────────┤ │
134
- │ │ At 50% for 24h: 8 × 1.27 × 0.50 × 24 = 121.9 core-hours │ │
135
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
136
- │ └─────────────────────────────────────────────────────────────────────┘ │
137
- │ │
138
- └─────────────────────────────────────────────────────────────────────────────┘
139
- ```
140
-
141
- ### Server CPUs
142
-
143
- ```
144
- ┌─────────────────────────────────────────────────────────────────────────────┐
145
- │ SERVER CPU EXAMPLES │
146
- ├─────────────────────────────────────────────────────────────────────────────┤
147
- │ │
148
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
149
- │ │ Intel Xeon E-2288G (8 cores @ 3.7 GHz) │ │
150
- │ ├─────────────────────────────────────────────────────────────────────┤ │
151
- │ │ At 30% for 24h: 8 × 1.23 × 0.30 × 24 = 70.8 core-hours │ │
152
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
153
- │ │ │ │
154
- │ │ At 50% for 24h: 8 × 1.23 × 0.50 × 24 = 118.1 core-hours │ │
155
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
156
- │ └─────────────────────────────────────────────────────────────────────┘ │
157
- │ │
158
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
159
- │ │ AMD EPYC 7302 (16 cores @ 3.0 GHz) │ │
160
- │ ├─────────────────────────────────────────────────────────────────────┤ │
161
- │ │ At 30% for 24h: 16 × 1.00 × 0.30 × 24 = 115.2 core-hours │ │
162
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
163
- │ │ │ │
164
- │ │ At 60% for 24h: 16 × 1.00 × 0.60 × 24 = 230.4 core-hours │ │
165
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
166
- │ └─────────────────────────────────────────────────────────────────────┘ │
167
- │ │
168
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
169
- │ │ AMD EPYC 7742 (64 cores @ 2.25 GHz) │ │
170
- │ ├─────────────────────────────────────────────────────────────────────┤ │
171
- │ │ At 20% for 24h: 64 × 0.75 × 0.20 × 24 = 230.4 core-hours │ │
172
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
173
- │ │ │ │
174
- │ │ At 50% for 24h: 64 × 0.75 × 0.50 × 24 = 576.0 core-hours │ │
175
- │ │ ✓ Qualifies for: ENTERPRISE tier (500,000 requests/day) │ │
176
- │ └─────────────────────────────────────────────────────────────────────┘ │
177
- │ │
178
- └─────────────────────────────────────────────────────────────────────────────┘
179
- ```
180
-
181
- ### VPS / Cloud Examples
182
-
183
- ```
184
- ┌─────────────────────────────────────────────────────────────────────────────┐
185
- │ VPS / CLOUD EXAMPLES │
186
- ├─────────────────────────────────────────────────────────────────────────────┤
187
- │ │
188
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
189
- │ │ Basic VPS (2 vCPU @ 2.5 GHz) - ~$5/month │ │
190
- │ ├─────────────────────────────────────────────────────────────────────┤ │
191
- │ │ At 80% for 24h: 2 × 0.83 × 0.80 × 24 = 31.9 core-hours │ │
192
- │ │ ✗ Not enough for Starter (needs 3 cores minimum) │ │
193
- │ └─────────────────────────────────────────────────────────────────────┘ │
194
- │ │
195
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
196
- │ │ Standard VPS (4 vCPU @ 2.5 GHz) - ~$20/month │ │
197
- │ ├─────────────────────────────────────────────────────────────────────┤ │
198
- │ │ At 50% for 24h: 4 × 0.83 × 0.50 × 24 = 39.8 core-hours │ │
199
- │ │ ✓ Qualifies for: PRO tier (20,000 requests/day) │ │
200
- │ └─────────────────────────────────────────────────────────────────────┘ │
201
- │ │
202
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
203
- │ │ Premium VPS (8 vCPU @ 3.0 GHz) - ~$80/month │ │
204
- │ ├─────────────────────────────────────────────────────────────────────┤ │
205
- │ │ At 50% for 24h: 8 × 1.00 × 0.50 × 24 = 96.0 core-hours │ │
206
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
207
- │ └─────────────────────────────────────────────────────────────────────┘ │
208
- │ │
209
- │ ┌─────────────────────────────────────────────────────────────────────┐ │
210
- │ │ AWS EC2 c5.4xlarge (16 vCPU @ 3.4 GHz) │ │
211
- │ ├─────────────────────────────────────────────────────────────────────┤ │
212
- │ │ At 40% for 24h: 16 × 1.13 × 0.40 × 24 = 173.6 core-hours │ │
213
- │ │ ✓ Qualifies for: BUSINESS tier (50,000 requests/day) │ │
214
- │ │ │ │
215
- │ │ At 70% for 24h: 16 × 1.13 × 0.70 × 24 = 303.7 core-hours │ │
216
- │ │ ✓ Qualifies for: ENTERPRISE tier (500,000 requests/day) │ │
217
- │ └─────────────────────────────────────────────────────────────────────┘ │
218
- │ │
219
- └─────────────────────────────────────────────────────────────────────────────┘
43
+ 1. USER SEARCHES 2. CHECK CACHE 3. SERVE RESULT
44
+ "spotify"
45
+ ┌─────────────┐
46
+ ┌──────┐ Coordinator ┌──────────┐
47
+ User │──search──▶ │ checks │──hit──▶ Worker │──result──▶ User
48
+ └──────┘ workers │ serves │
49
+ └─────────────┘ └──────────┘
50
+
51
+ miss
52
+
53
+ ┌──────────┐
54
+ Server │──result──▶ User + Distribute to Workers
55
+ process
56
+ └──────────┘
57
+ ```
58
+
59
+ ### What Your Worker Does vs. Doesn't Do
60
+
61
+ ```
62
+ DOES ❌ DOESN'T
63
+ ───────────────────────────────── ─────────────────────────────────
64
+ • Store search RESULTS • Have the search INDEX
65
+ Serve cached results • Process raw documents
66
+ Use 50-200MB RAM • Use significant CPU
67
+ Use 500MB-2GB disk • Access your files
68
+ Connect via WebSocket • Run arbitrary code
69
+ • Earn you API access • Collect your data
220
70
  ```
221
71
 
222
72
  ## Quick Start
223
73
 
224
- ### 1. Get Your Token
74
+ ```bash
75
+ # 1. Get your token at https://worker.avalw.org
76
+ # 2. Run the worker:
77
+ npx @avalw/search-worker --token YOUR_TOKEN
78
+ ```
225
79
 
226
- Visit [worker.avalw.org](https://worker.avalw.org) and create a free account. You'll receive:
227
- - **Account Hash** - Your unique identifier (save this!)
228
- - **Worker Token** - Used to run the worker
80
+ That's it! Your worker will connect and start contributing.
229
81
 
230
- ### 2. Install the Worker
82
+ ## Installation
231
83
 
232
84
  ```bash
85
+ # Global install
233
86
  npm install -g @avalw/search-worker
87
+
88
+ # Or use npx (no install needed)
89
+ npx @avalw/search-worker --token YOUR_TOKEN
234
90
  ```
235
91
 
236
- ### 3. Run the Worker
92
+ ## What's New in v2.1.0
237
93
 
238
- ```bash
239
- avalw-worker YOUR_WORKER_TOKEN
240
94
  ```
95
+ ┌────────────────────────────────────────────────────────────────┐
96
+ │ INTELLIGENT CACHE SYSTEM │
97
+ ├────────────────────────────────────────────────────────────────┤
98
+ │ │
99
+ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
100
+ │ │ Size Limits │ │ Time-Based │ │ Popularity │ │
101
+ │ │ 100MB - 2GB │ │ Eviction │ │ Scoring │ │
102
+ │ └─────────────┘ └─────────────┘ └─────────────┘ │
103
+ │ │
104
+ │ • Cache up to 2GB of search results │
105
+ │ • Auto-remove queries unused for 7+ days │
106
+ │ • Popular queries stay cached longer │
107
+ │ • Background cleanup every hour │
108
+ │ │
109
+ └────────────────────────────────────────────────────────────────┘
110
+ ```
111
+
112
+ ## Command Line Options
241
113
 
242
- You'll see real-time stats:
114
+ ```bash
115
+ # Basic usage (500MB cache, 7 day retention)
116
+ npx @avalw/search-worker --token abc123
117
+
118
+ # Custom cache size (100-2048 MB)
119
+ npx @avalw/search-worker --token abc123 --cache-size 1024
120
+
121
+ # Custom retention (1-30 days)
122
+ npx @avalw/search-worker --token abc123 --max-age 14
123
+
124
+ # Full customization
125
+ npx @avalw/search-worker \
126
+ --token abc123 \
127
+ --cache-size 1024 \
128
+ --max-age 14
243
129
  ```
244
- ╔═══════════════════════════════════════════════════════════════════╗
245
- ║ AVALW Search Worker v1.1.0 ║
246
- ╠═══════════════════════════════════════════════════════════════════╣
247
- ║ Free Search API in exchange for compute ║
248
- ╚═══════════════════════════════════════════════════════════════════╝
249
130
 
250
- System Info:
251
- ├─ CPU: Intel(R) Core(TM) i7-10700 @ 2.90GHz
252
- ├─ Cores: 8
253
- ├─ Speed Factor: 0.97x (normalized to 3.0 GHz)
254
- └─ Memory: 32 GB
131
+ ### All Options
255
132
 
256
- Worker Status:
257
- ├─ Token: abc123def456...
258
- ├─ API URL: https://worker.avalw.org
259
- └─ Target Usage: 50%
133
+ ```
134
+ ┌──────────────────┬─────────────────┬───────────────────────────────────┐
135
+ Option │ Default │ Description │
136
+ ├──────────────────┼─────────────────┼───────────────────────────────────┤
137
+ │ -t, --token │ $AVALW_TOKEN │ Your worker authentication token │
138
+ │ -s, --cache-size │ 500 │ Max cache size in MB (100-2048) │
139
+ │ -a, --max-age │ 7 │ Days to keep unused queries (1-30)│
140
+ │ -h, --help │ │ Show help │
141
+ │ -v, --version │ │ Show version │
142
+ └──────────────────┴─────────────────┴───────────────────────────────────┘
143
+ ```
260
144
 
261
- [10:30:45] Heartbeat OK
262
- ├─ Core-Hours Today: 46.5 / 72 needed for BUSINESS
263
- ├─ Current Tier: PRO (20,000 req/day)
264
- ├─ Usage Today: 1,234 / 20,000
265
- └─ Online: 12h 35m
145
+ ### Environment Variables
266
146
 
267
- Press Ctrl+C to stop.
147
+ ```bash
148
+ export AVALW_WORKER_TOKEN=your-token-here
149
+ export AVALW_CACHE_SIZE_MB=1024
150
+ export AVALW_MAX_AGE_DAYS=14
151
+ npx @avalw/search-worker
268
152
  ```
269
153
 
270
- ### 4. Use the Search API
154
+ ## Programmatic Usage
271
155
 
272
156
  ```javascript
273
- const response = await fetch(
274
- 'https://worker.avalw.org/api/search?q=your+query&token=YOUR_TOKEN'
275
- );
276
- const results = await response.json();
157
+ const { createWorker } = require('@avalw/search-worker');
158
+
159
+ const worker = createWorker({
160
+ workerToken: 'your-token-here',
161
+
162
+ // Cache configuration
163
+ cacheSizeMB: 1024, // 1GB cache
164
+ maxAgeDays: 14, // 14 day retention
165
+
166
+ // Event handlers
167
+ onConnected: (w) => console.log('Connected to coordinator'),
168
+ onDisconnected: (w) => console.log('Disconnected'),
169
+ onCacheHit: (key) => console.log('Served:', key),
170
+ onCacheStore: (key) => console.log('Cached:', key),
171
+ onError: (err) => console.error('Error:', err)
172
+ });
173
+
174
+ // Connect
175
+ worker.connect();
176
+
177
+ // Get stats
178
+ const stats = worker.getStats();
179
+ console.log(`Cache: ${stats.cache.sizeFormatted} / ${stats.cache.maxSizeFormatted}`);
180
+ console.log(`Hit rate: ${stats.hitRate}%`);
181
+
182
+ // Runtime configuration
183
+ worker.setCacheSize(2048); // Change to 2GB
184
+ worker.setCacheMaxAge(30); // Change to 30 days
185
+
186
+ // Cleanup
187
+ worker.disconnect();
277
188
  ```
278
189
 
279
- ## Running as a Service
190
+ ## API Tiers & Rewards
280
191
 
281
- ### Using PM2 (Recommended)
192
+ Your contribution is measured in Core-Hours:
282
193
 
283
- ```bash
284
- # Install PM2
285
- npm install -g pm2
194
+ ```
195
+ ┌─────────────────────────────────────────────────────────────────────┐
196
+ │ CORE-HOURS FORMULA │
197
+ ├─────────────────────────────────────────────────────────────────────┤
198
+ │ │
199
+ │ Core-Hours = Cores × (CPU Speed ÷ 3.0 GHz) × Usage% × Hours │
200
+ │ │
201
+ │ Example: 8 cores × (3.5 GHz ÷ 3.0 GHz) × 80% × 1 hour │
202
+ │ = 8 × 1.17 × 0.8 × 1 = 7.5 Core-Hours │
203
+ │ │
204
+ └─────────────────────────────────────────────────────────────────────┘
205
+ ```
206
+
207
+ ### Tier Benefits
208
+
209
+ ```
210
+ ┌─────────────┬────────────┬───────────┬─────────────────┐
211
+ │ Tier │ Core-Hours │ Min Cores │ API Requests │
212
+ ├─────────────┼────────────┼───────────┼─────────────────┤
213
+ │ Starter │ 3 │ 3 │ 1,000/day │
214
+ │ Basic │ 12 │ 4 │ 5,000/day │
215
+ │ Pro │ 36 │ 6 │ 20,000/day │
216
+ │ Business │ 72 │ 8 │ 50,000/day │
217
+ │ Enterprise │ 240 │ 16 │ 500,000/day │
218
+ └─────────────┴────────────┴───────────┴─────────────────┘
219
+ ```
286
220
 
287
- # Start worker with 50% CPU target
288
- pm2 start avalw-worker -- YOUR_WORKER_TOKEN
221
+ ## Intelligent Cache Details
289
222
 
290
- # Or specify custom CPU percentage
291
- pm2 start avalw-worker -- YOUR_WORKER_TOKEN --cpu 30
223
+ ### How Eviction Works
292
224
 
293
- # Save for auto-restart
294
- pm2 save
295
- pm2 startup
225
+ ```
226
+ ┌─────────────────────────────────────────────────────────────┐
227
+ │ EVICTION PRIORITY │
228
+ ├─────────────────────────────────────────────────────────────┤
229
+ │ │
230
+ │ 1. EXPIRED TTL │
231
+ │ └── Items past their time-to-live (5 min default) │
232
+ │ │
233
+ │ 2. MAX AGE EXCEEDED │
234
+ │ └── Items not accessed for N days (7 days default) │
235
+ │ │
236
+ │ 3. LOWEST POPULARITY │
237
+ │ └── Score = log2(accessCount) × recency × stability │
238
+ │ │
239
+ │ Priority: 1 > 2 > 3 (expired items removed first) │
240
+ │ │
241
+ └─────────────────────────────────────────────────────────────┘
296
242
  ```
297
243
 
298
- ### Using systemd (Linux)
244
+ ### Popularity Scoring
299
245
 
300
- Create `/etc/systemd/system/avalw-worker.service`:
246
+ ```
247
+ Score = log2(accessCount + 1) × recencyFactor × stabilityFactor
248
+
249
+ ┌─────────────────┬─────────────────────────────────────────┐
250
+ │ Factor │ Description │
251
+ ├─────────────────┼─────────────────────────────────────────┤
252
+ │ accessCount │ Number of times the query was accessed │
253
+ │ recencyFactor │ 1.0 → 0.0 over 7 days since last access │
254
+ │ stabilityFactor │ Higher for consistent access patterns │
255
+ └─────────────────┴─────────────────────────────────────────┘
256
+
257
+ Example: Query accessed 100 times, last accessed 1 day ago
258
+ Score = log2(101) × 0.86 × 1.2 = 6.65 × 0.86 × 1.2 = 6.86
259
+ ```
260
+
261
+ ## Resource Usage
262
+
263
+ ```
264
+ ┌──────────────────────────────────────────────────────────┐
265
+ │ TYPICAL RESOURCE USAGE │
266
+ ├──────────────────────────────────────────────────────────┤
267
+ │ │
268
+ │ CPU: 1-5% [▓░░░░░░░░░░░░░░░░░░░] minimal │
269
+ │ RAM: 50-200MB [▓▓▓▓░░░░░░░░░░░░░░░░] light │
270
+ │ Disk: 500MB-2GB [▓▓▓▓▓▓▓▓░░░░░░░░░░░░] configurable │
271
+ │ Network: Low [▓▓░░░░░░░░░░░░░░░░░░] WebSocket │
272
+ │ │
273
+ └──────────────────────────────────────────────────────────┘
274
+ ```
275
+
276
+ ## Privacy & Security
277
+
278
+ ```
279
+ ┌────────────────────────────────────────────────────────────────┐
280
+ │ PRIVACY GUARANTEES │
281
+ ├────────────────────────────────────────────────────────────────┤
282
+ │ │
283
+ │ ✓ Workers cache RESULTS only, not the search index │
284
+ │ ✓ No IP addresses are logged │
285
+ │ ✓ Workers don't see who requested a search │
286
+ │ ✓ All communication encrypted (WSS/HTTPS) │
287
+ │ ✓ No access to your local files │
288
+ │ ✓ Open source - audit the code yourself │
289
+ │ │
290
+ └────────────────────────────────────────────────────────────────┘
291
+ ```
292
+
293
+ ## Running as a Service
294
+
295
+ ### Linux (systemd)
296
+
297
+ ```bash
298
+ # Create service file
299
+ sudo nano /etc/systemd/system/avalw-worker.service
300
+ ```
301
301
 
302
302
  ```ini
303
303
  [Unit]
@@ -306,8 +306,11 @@ After=network.target
306
306
 
307
307
  [Service]
308
308
  Type=simple
309
- User=your-user
310
- ExecStart=/usr/bin/avalw-worker YOUR_WORKER_TOKEN
309
+ User=nobody
310
+ Environment=AVALW_WORKER_TOKEN=your-token-here
311
+ Environment=AVALW_CACHE_SIZE_MB=1024
312
+ Environment=AVALW_MAX_AGE_DAYS=14
313
+ ExecStart=/usr/bin/npx @avalw/search-worker
311
314
  Restart=always
312
315
  RestartSec=10
313
316
 
@@ -315,136 +318,103 @@ RestartSec=10
315
318
  WantedBy=multi-user.target
316
319
  ```
317
320
 
318
- Then:
319
321
  ```bash
322
+ # Enable and start
323
+ sudo systemctl daemon-reload
320
324
  sudo systemctl enable avalw-worker
321
325
  sudo systemctl start avalw-worker
326
+
327
+ # Check status
328
+ sudo systemctl status avalw-worker
322
329
  ```
323
330
 
324
- ### Using Docker
331
+ ### Docker
325
332
 
326
333
  ```dockerfile
327
- FROM node:20-alpine
334
+ FROM node:18-alpine
328
335
  RUN npm install -g @avalw/search-worker
329
- CMD ["avalw-worker", "YOUR_WORKER_TOKEN"]
336
+ ENV AVALW_WORKER_TOKEN=your-token-here
337
+ ENV AVALW_CACHE_SIZE_MB=1024
338
+ ENV AVALW_MAX_AGE_DAYS=14
339
+ CMD ["avalw-worker"]
330
340
  ```
331
341
 
332
342
  ```bash
333
343
  docker build -t avalw-worker .
334
- docker run -d --name avalw-worker avalw-worker
344
+ docker run -d --name avalw avalw-worker
335
345
  ```
336
346
 
337
- ## API Reference
338
-
339
- ### Search Endpoint
347
+ ### PM2
340
348
 
341
- ```
342
- GET https://worker.avalw.org/api/search
349
+ ```bash
350
+ pm2 start avalw-worker --name "avalw" -- --token YOUR_TOKEN --cache-size 1024
351
+ pm2 save
352
+ pm2 startup
343
353
  ```
344
354
 
345
- | Parameter | Type | Required | Description |
346
- |-----------|--------|----------|--------------------------------|
347
- | q | string | Yes | Search query |
348
- | token | string | Yes | Your worker token |
349
- | page | number | No | Page number (default: 1) |
350
- | limit | number | No | Results per page (default: 10) |
355
+ ### Windows (Task Scheduler)
351
356
 
352
- **Response:**
353
- ```json
354
- {
355
- "success": true,
356
- "results": [
357
- {
358
- "title": "Example Result",
359
- "url": "https://example.com",
360
- "snippet": "This is a snippet..."
361
- }
362
- ],
363
- "total": 100,
364
- "page": 1,
365
- "tier": "PRO",
366
- "usage": {
367
- "today": 1234,
368
- "limit": 20000,
369
- "core_hours": 46.5
370
- }
371
- }
357
+ ```batch
358
+ @echo off
359
+ set AVALW_WORKER_TOKEN=your-token-here
360
+ set AVALW_CACHE_SIZE_MB=1024
361
+ npx @avalw/search-worker
372
362
  ```
373
363
 
374
- ## FAQ
375
-
376
- ### Why do I need minimum 3 cores?
377
-
378
- The AVALW network requires meaningful contributions to remain sustainable. A 3-core minimum ensures:
379
- - Fair distribution of compute power
380
- - Quality of service for all users
381
- - Sustainable network operation
382
-
383
- ### Can I run on a 2-core VPS?
384
-
385
- Unfortunately, 2 cores don't meet the minimum requirement. Consider:
386
- - Upgrading to a 4-core VPS
387
- - Running on a different server with more cores
388
- - Combining with another server (coming soon: multi-worker support)
389
-
390
- ### How is my tier calculated?
391
-
392
- Your tier is recalculated every hour based on your rolling 24-hour core-hours contribution. The formula:
364
+ ## Troubleshooting
393
365
 
394
366
  ```
395
- Core-Hours = Cores × (Speed ÷ 3.0) × Usage% × Hours
367
+ ┌─────────────────────────────────────────────────────────────────┐
368
+ │ COMMON ISSUES │
369
+ ├─────────────────────────────────────────────────────────────────┤
370
+ │ │
371
+ │ "Connection refused" │
372
+ │ └── Check internet connection, firewall settings │
373
+ │ │
374
+ │ "Invalid token" │
375
+ │ └── Get a new token at https://worker.avalw.org │
376
+ │ │
377
+ │ "Cache full, high eviction rate" │
378
+ │ └── Increase --cache-size or decrease --max-age │
379
+ │ │
380
+ │ "Memory usage too high" │
381
+ │ └── Decrease --cache-size (minimum 100MB) │
382
+ │ │
383
+ │ "Worker keeps disconnecting" │
384
+ │ └── Check network stability, worker will auto-reconnect │
385
+ │ │
386
+ └─────────────────────────────────────────────────────────────────┘
396
387
  ```
397
388
 
398
- ### What if my server goes offline?
399
-
400
- Your core-hours accumulate only while online. If you go offline:
401
- - Your accumulated core-hours for the day remain
402
- - Your tier may drop if you don't maintain the required hours
403
- - API calls will fail until your worker reconnects
404
-
405
- ## Security
389
+ ## System Requirements
406
390
 
407
- - **No data collection**: We don't log search queries
408
- - **No tracking**: No cookies, no fingerprinting
409
- - **Open protocol**: Transparent heartbeat mechanism
410
- - **Your server, your control**: Worker runs on your infrastructure
391
+ ```
392
+ ┌────────────────┬────────────────────────────────────┐
393
+ Component │ Requirement │
394
+ ├────────────────┼────────────────────────────────────┤
395
+ │ Node.js │ 14.0.0 or higher │
396
+ │ CPU │ 3+ cores for Starter tier │
397
+ │ RAM │ 512MB+ free │
398
+ │ Disk │ 500MB - 2GB for cache │
399
+ │ Network │ Stable internet, WebSocket support │
400
+ │ OS │ Windows, macOS, Linux │
401
+ └────────────────┴────────────────────────────────────┘
402
+ ```
411
403
 
412
404
  ## Support
413
405
 
414
- - Website: [worker.avalw.org](https://worker.avalw.org)
406
+ - Dashboard: [worker.avalw.org](https://worker.avalw.org)
407
+ - Documentation: [worker.avalw.org/protocol](https://worker.avalw.org/protocol)
415
408
  - Email: contact@avalw.com
409
+ - Search Engine: [avalw.org](https://avalw.org)
416
410
 
417
411
  ## License
418
412
 
419
- MIT License
420
-
421
- Copyright (c) 2026 AVALW
422
-
423
- Permission is hereby granted, free of charge, to any person obtaining a copy
424
- of this software and associated documentation files (the "Software"), to deal
425
- in the Software without restriction, including without limitation the rights
426
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
427
- copies of the Software, and to permit persons to whom the Software is
428
- furnished to do so, subject to the following conditions:
429
-
430
- The above copyright notice and this permission notice shall be included in all
431
- copies or substantial portions of the Software.
432
-
433
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
434
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
435
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
436
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
437
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
438
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
439
- SOFTWARE.
413
+ MIT License - Free to use, modify, and distribute.
440
414
 
441
415
  ---
442
416
 
443
- Made with privacy in mind by [AVALW](https://cronos.avalw.com/about)
444
-
445
- ### Our Projects
446
-
447
- - [AVALW Search](https://avalw.org) - Privacy-focused search engine
448
- - [Cronos Browser](https://cronos.avalw.com) - Secure, private browser
449
- - [AVALW Protocol](https://avalw.com) - Decentralized communication protocol
450
- - [Worker API](https://worker.avalw.org) - This project
417
+ ```
418
+ Made with transparency in mind by AVALW
419
+ https://avalw.com
420
+ ```