|
2 | 2 |
|
3 | 3 | httpjail provides three different rule engines for evaluating HTTP requests. Each has different trade-offs in terms of performance, flexibility, and ease of use. |
4 | 4 |
|
5 | | -## Available Engines |
6 | | - |
7 | | -### JavaScript (V8) |
8 | | - |
9 | | -Fast, secure JavaScript evaluation using the V8 engine. Best for most use cases. |
10 | | - |
11 | | -**Pros:** |
12 | | - |
13 | | -- ⚡ Fastest performance (compiled and cached) |
14 | | -- 🔒 Sandboxed execution environment |
15 | | -- 📝 Familiar JavaScript syntax |
16 | | -- 🎯 Direct access to request properties |
17 | | - |
18 | | -**Cons:** |
19 | | - |
20 | | -- Limited to JavaScript expressions |
21 | | -- No external tool integration |
22 | | -- No stateful operations between requests |
23 | | - |
24 | | -**Use when:** You need high-performance filtering with simple to moderate logic. |
25 | | - |
26 | | -### Shell Scripts |
27 | | - |
28 | | -Execute shell scripts for each request with full system access. |
29 | | - |
30 | | -**Pros:** |
31 | | - |
32 | | -- 🔧 Full system access and tool integration |
33 | | -- 📊 Can maintain state between requests |
34 | | -- 🔗 Integrate with existing scripts and tools |
35 | | -- 💾 Can query databases or external services |
36 | | - |
37 | | -**Cons:** |
38 | | - |
39 | | -- Slow (process spawn per request) |
40 | | -- Security considerations with shell execution |
41 | | -- Platform-specific behavior |
42 | | - |
43 | | -**Use when:** You need to integrate with existing tools or require complex system interactions. |
44 | | - |
45 | | -### Line Processor |
46 | | - |
47 | | -Stream-based processing with line-by-line evaluation. |
48 | | - |
49 | | -**Pros:** |
50 | | - |
51 | | -- 🚀 Long-running process (no spawn overhead) |
52 | | -- 📈 Can maintain state across requests |
53 | | -- 🐍 Language agnostic (Python, Ruby, etc.) |
54 | | -- 🔄 Bi-directional communication |
55 | | - |
56 | | -**Cons:** |
57 | | - |
58 | | -- More complex to implement |
59 | | -- Requires handling the protocol correctly |
60 | | -- Process management considerations |
61 | | - |
62 | | -**Use when:** You have high request volume and need stateful processing or want to use a specific language. |
63 | | - |
64 | | -## Performance Comparison |
65 | | - |
66 | | -| Engine | Startup Time | Per-Request Overhead | Memory Usage | Stateful | |
67 | | -| -------------- | ------------ | -------------------- | ------------ | -------- | |
68 | | -| JavaScript | Fast | ~0.1ms | Low | No | |
69 | | -| Shell Script | None | ~10-50ms | Variable | No\* | |
70 | | -| Line Processor | Slow | ~0.5ms | Variable | Yes | |
71 | | - |
72 | | -\*Shell scripts can use files for state but each invocation is independent |
73 | | - |
74 | | -## Choosing a Rule Engine |
75 | | - |
76 | | -### For Production Use |
77 | | - |
78 | | -**JavaScript** is recommended for production environments due to: |
79 | | - |
80 | | -- Excellent performance |
81 | | -- Predictable resource usage |
82 | | -- Security isolation |
83 | | -- Simple deployment |
84 | | - |
85 | | -### For Development/Testing |
86 | | - |
87 | | -**Shell scripts** work well for: |
88 | | - |
89 | | -- Rapid prototyping |
90 | | -- Integration testing |
91 | | -- Debugging complex scenarios |
92 | | - |
93 | | -### For Complex Filtering |
94 | | - |
95 | | -**Line Processor** excels at: |
96 | | - |
97 | | -- Machine learning models |
98 | | -- Statistical analysis |
99 | | -- Complex stateful logic |
100 | | -- Custom protocols |
| 5 | +## Engine Comparison |
| 6 | + |
| 7 | +| Feature | JavaScript (V8) | Shell Script | Line Processor | |
| 8 | +|---------|----------------|--------------|----------------| |
| 9 | +| **Performance** | | | | |
| 10 | +| Startup Time | Fast (~5ms) | None | Slow (~100ms) | |
| 11 | +| Per-Request Overhead | ~0.1ms | ~10-50ms | ~0.5ms | |
| 12 | +| Memory Usage | Low (5-10MB) | Variable | Variable | |
| 13 | +| Throughput | >10K req/s | ~50 req/s | ~2K req/s | |
| 14 | +| **Capabilities** | | | | |
| 15 | +| Stateful Processing | ❌ | ❌* | ✅ | |
| 16 | +| External Tool Access | ❌ | ✅ | ✅ | |
| 17 | +| Database Integration | ❌ | ✅ | ✅ | |
| 18 | +| Language Choice | JS only | Bash/Shell | Any | |
| 19 | +| Sandboxed Execution | ✅ | ❌ | Depends | |
| 20 | +| **Development** | | | | |
| 21 | +| Setup Complexity | Simple | Simple | Moderate | |
| 22 | +| Debug Difficulty | Easy | Easy | Moderate | |
| 23 | +| Hot Reload | ❌ | ✅ | ❌ | |
| 24 | +| **Best For** | | | | |
| 25 | +| Primary Use Case | Production filtering | System integration | Stateful logic | |
| 26 | +| Request Volume | High | Low | Medium | |
| 27 | +| Security Level | Untrusted rules | Trusted only | Depends on impl | |
| 28 | + |
| 29 | +*Shell scripts can use files for state but each invocation is independent |
101 | 30 |
|
102 | 31 | ## Examples |
103 | 32 |
|
|
0 commit comments