@0xobelisk/graphql-server 1.2.0-pre.100
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/.turbo/turbo-build.log +8 -0
- package/DUAL_POOL_CONFIG.md +188 -0
- package/Dockerfile +35 -0
- package/LICENSE +92 -0
- package/README.md +487 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +206 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/subscription-config.d.ts +80 -0
- package/dist/config/subscription-config.d.ts.map +1 -0
- package/dist/config/subscription-config.js +158 -0
- package/dist/config/subscription-config.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/all-fields-filter-plugin.d.ts +4 -0
- package/dist/plugins/all-fields-filter-plugin.d.ts.map +1 -0
- package/dist/plugins/all-fields-filter-plugin.js +132 -0
- package/dist/plugins/all-fields-filter-plugin.js.map +1 -0
- package/dist/plugins/database-introspector.d.ts +23 -0
- package/dist/plugins/database-introspector.d.ts.map +1 -0
- package/dist/plugins/database-introspector.js +96 -0
- package/dist/plugins/database-introspector.js.map +1 -0
- package/dist/plugins/enhanced-playground.d.ts +9 -0
- package/dist/plugins/enhanced-playground.d.ts.map +1 -0
- package/dist/plugins/enhanced-playground.js +113 -0
- package/dist/plugins/enhanced-playground.js.map +1 -0
- package/dist/plugins/enhanced-server-manager.d.ts +29 -0
- package/dist/plugins/enhanced-server-manager.d.ts.map +1 -0
- package/dist/plugins/enhanced-server-manager.js +262 -0
- package/dist/plugins/enhanced-server-manager.js.map +1 -0
- package/dist/plugins/index.d.ts +9 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +26 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/postgraphile-config.d.ts +94 -0
- package/dist/plugins/postgraphile-config.d.ts.map +1 -0
- package/dist/plugins/postgraphile-config.js +138 -0
- package/dist/plugins/postgraphile-config.js.map +1 -0
- package/dist/plugins/query-filter.d.ts +4 -0
- package/dist/plugins/query-filter.d.ts.map +1 -0
- package/dist/plugins/query-filter.js +42 -0
- package/dist/plugins/query-filter.js.map +1 -0
- package/dist/plugins/simple-naming.d.ts +4 -0
- package/dist/plugins/simple-naming.d.ts.map +1 -0
- package/dist/plugins/simple-naming.js +79 -0
- package/dist/plugins/simple-naming.js.map +1 -0
- package/dist/plugins/welcome-page.d.ts +11 -0
- package/dist/plugins/welcome-page.d.ts.map +1 -0
- package/dist/plugins/welcome-page.js +203 -0
- package/dist/plugins/welcome-page.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +265 -0
- package/dist/server.js.map +1 -0
- package/dist/universal-subscriptions.d.ts +32 -0
- package/dist/universal-subscriptions.d.ts.map +1 -0
- package/dist/universal-subscriptions.js +318 -0
- package/dist/universal-subscriptions.js.map +1 -0
- package/dist/utils/logger/index.d.ts +80 -0
- package/dist/utils/logger/index.d.ts.map +1 -0
- package/dist/utils/logger/index.js +230 -0
- package/dist/utils/logger/index.js.map +1 -0
- package/docker-compose.yml +46 -0
- package/eslint.config.mjs +3 -0
- package/package.json +78 -0
- package/src/cli.ts +232 -0
- package/src/config/subscription-config.ts +243 -0
- package/src/index.ts +11 -0
- package/src/plugins/README.md +138 -0
- package/src/plugins/all-fields-filter-plugin.ts +158 -0
- package/src/plugins/database-introspector.ts +126 -0
- package/src/plugins/enhanced-playground.ts +121 -0
- package/src/plugins/enhanced-server-manager.ts +314 -0
- package/src/plugins/index.ts +9 -0
- package/src/plugins/postgraphile-config.ts +182 -0
- package/src/plugins/query-filter.ts +50 -0
- package/src/plugins/simple-naming.ts +105 -0
- package/src/plugins/welcome-page.ts +218 -0
- package/src/server.ts +324 -0
- package/src/universal-subscriptions.ts +397 -0
- package/src/utils/logger/README.md +209 -0
- package/src/utils/logger/index.ts +275 -0
- package/sui-indexer-schema.graphql +3691 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
> @0xobelisk/graphql-server@1.2.0-pre.100 build /home/runner/work/dubhe/dubhe/packages/graphql-server
|
|
3
|
+
> pnpm run type-check && tsc
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> @0xobelisk/graphql-server@1.2.0-pre.100 type-check /home/runner/work/dubhe/dubhe/packages/graphql-server
|
|
7
|
+
> tsc --noEmit
|
|
8
|
+
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Unified Connection Pool Configuration
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The GraphQL server now uses a **unified connection pool architecture**, with a single connection pool handling all GraphQL operations:
|
|
6
|
+
|
|
7
|
+
- Query
|
|
8
|
+
- Mutation
|
|
9
|
+
- Subscription
|
|
10
|
+
|
|
11
|
+
## Connection Pool Parameters
|
|
12
|
+
|
|
13
|
+
### Core Parameters
|
|
14
|
+
|
|
15
|
+
1. **`max`** - Maximum Connections
|
|
16
|
+
|
|
17
|
+
- The maximum number of connections the pool can create
|
|
18
|
+
- Should be set based on database server capacity and application requirements
|
|
19
|
+
|
|
20
|
+
2. **`min`** - Minimum Connections
|
|
21
|
+
|
|
22
|
+
- The minimum number of connections the pool maintains
|
|
23
|
+
- Usually set to around 10% of `max`
|
|
24
|
+
|
|
25
|
+
3. **`connectionTimeoutMillis`** - Connection Timeout
|
|
26
|
+
|
|
27
|
+
- Timeout for acquiring connections from the pool
|
|
28
|
+
- Balanced value: 10 seconds (supports various operations)
|
|
29
|
+
|
|
30
|
+
4. **`idleTimeoutMillis`** - Idle Timeout
|
|
31
|
+
|
|
32
|
+
- How long a connection stays idle before being disconnected
|
|
33
|
+
- Balanced value: 5 minutes (supports subscriptions while avoiding resource waste)
|
|
34
|
+
|
|
35
|
+
5. **`maxLifetimeSeconds`** - Maximum Connection Lifetime
|
|
36
|
+
- Maximum lifetime of a connection, after which it's forcibly rotated
|
|
37
|
+
- Balanced value: 1 hour (prevents connection leaks)
|
|
38
|
+
|
|
39
|
+
## Current Configuration
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
const pgPool = new Pool({
|
|
43
|
+
connectionString: DATABASE_URL,
|
|
44
|
+
max: config.maxConnections, // Total connections
|
|
45
|
+
min: Math.min(5, Math.floor(config.maxConnections * 0.1)), // 10% minimum connections
|
|
46
|
+
connectionTimeoutMillis: 10000, // 10 second timeout
|
|
47
|
+
idleTimeoutMillis: 600000, // 10 minute idle cleanup
|
|
48
|
+
maxLifetimeSeconds: 3600, // 1 hour rotation
|
|
49
|
+
allowExitOnIdle: config.env === 'development'
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Monitoring Endpoints
|
|
54
|
+
|
|
55
|
+
### `/pool-status` - Connection Pool Status
|
|
56
|
+
|
|
57
|
+
Returns detailed status of the current connection pool:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"status": "ok",
|
|
62
|
+
"connectionPool": {
|
|
63
|
+
"totalCount": 25,
|
|
64
|
+
"idleCount": 20,
|
|
65
|
+
"waitingCount": 0,
|
|
66
|
+
"maxConnections": 1000,
|
|
67
|
+
"minConnections": 5
|
|
68
|
+
},
|
|
69
|
+
"strategy": "single-pool-unified",
|
|
70
|
+
"operations": ["query", "mutation", "subscription"],
|
|
71
|
+
"timestamp": "2024-01-20T10:30:45.123Z",
|
|
72
|
+
"uptime": 3600.5,
|
|
73
|
+
"memory": {
|
|
74
|
+
"rss": 52428800,
|
|
75
|
+
"heapTotal": 29360128,
|
|
76
|
+
"heapUsed": 18874568,
|
|
77
|
+
"external": 1089024
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Status Field Descriptions
|
|
83
|
+
|
|
84
|
+
- **totalCount**: Current active connections
|
|
85
|
+
- **idleCount**: Idle connections
|
|
86
|
+
- **waitingCount**: Clients waiting for connections
|
|
87
|
+
- **maxConnections**: Configured maximum connections
|
|
88
|
+
- **minConnections**: Configured minimum connections
|
|
89
|
+
|
|
90
|
+
## Configuration Recommendations
|
|
91
|
+
|
|
92
|
+
### Basic Configuration
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Small applications (< 100 concurrent)
|
|
96
|
+
--max-connections 100
|
|
97
|
+
|
|
98
|
+
# Medium applications (100-500 concurrent)
|
|
99
|
+
--max-connections 300
|
|
100
|
+
|
|
101
|
+
# Large applications (500+ concurrent)
|
|
102
|
+
--max-connections 1000
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Subscription-Heavy Applications
|
|
106
|
+
|
|
107
|
+
If your application has many long-term subscription connections:
|
|
108
|
+
|
|
109
|
+
- Appropriately increase `idleTimeoutMillis` to 10-15 minutes
|
|
110
|
+
- Increase `maxLifetimeSeconds` to 2-4 hours
|
|
111
|
+
- Monitor `idleCount` to ensure sufficient idle connections for new requests
|
|
112
|
+
|
|
113
|
+
### Query-Heavy Applications
|
|
114
|
+
|
|
115
|
+
If your application is primarily short-term queries/mutations:
|
|
116
|
+
|
|
117
|
+
- Reduce `idleTimeoutMillis` to 1-2 minutes
|
|
118
|
+
- Reduce `maxLifetimeSeconds` to 30 minutes
|
|
119
|
+
- Monitor `waitingCount` to ensure the connection pool is large enough
|
|
120
|
+
|
|
121
|
+
## Performance Optimization
|
|
122
|
+
|
|
123
|
+
### Connection Count Calculation Formula
|
|
124
|
+
|
|
125
|
+
Recommended maximum connection calculation:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
maxConnections = min(
|
|
129
|
+
Database max connections * 0.8,
|
|
130
|
+
(CPU cores * 2) + effective disk count,
|
|
131
|
+
Expected concurrent users * 1.2
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Monitoring Metrics
|
|
136
|
+
|
|
137
|
+
Key monitoring metrics:
|
|
138
|
+
|
|
139
|
+
1. **Connection Utilization** = `totalCount / maxConnections`
|
|
140
|
+
- Target: 60-80%
|
|
141
|
+
2. **Wait Queue** = `waitingCount`
|
|
142
|
+
- Target: < 5% of time with waiting
|
|
143
|
+
3. **Idle Rate** = `idleCount / totalCount`
|
|
144
|
+
- Target: 20-40%
|
|
145
|
+
|
|
146
|
+
## Troubleshooting
|
|
147
|
+
|
|
148
|
+
### Common Issues
|
|
149
|
+
|
|
150
|
+
1. **Connection Timeout**
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
Error: timeout acquiring a connection from the pool
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Solution: Increase `maxConnections` or optimize query performance
|
|
157
|
+
|
|
158
|
+
2. **Insufficient Connections**
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
Error: remaining connection slots are reserved
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Solution: Check database connection limits, adjust `maxConnections`
|
|
165
|
+
|
|
166
|
+
3. **Subscription Disconnections**
|
|
167
|
+
- Check if `idleTimeoutMillis` is too short
|
|
168
|
+
- Verify network stability
|
|
169
|
+
- Monitor `maxLifetimeSeconds` settings
|
|
170
|
+
|
|
171
|
+
### Tuning Steps
|
|
172
|
+
|
|
173
|
+
1. **Baseline Testing**: Record connection usage under normal load
|
|
174
|
+
2. **Stress Testing**: Simulate high load, observe `waitingCount`
|
|
175
|
+
3. **Gradual Adjustment**: Incrementally increase `maxConnections`, observe effects
|
|
176
|
+
4. **Continuous Monitoring**: Use `/pool-status` endpoint for ongoing monitoring
|
|
177
|
+
|
|
178
|
+
## Best Practices
|
|
179
|
+
|
|
180
|
+
1. **Progressive Scaling**: Start with smaller connection counts, gradually increase based on needs
|
|
181
|
+
2. **Monitoring-Driven**: Base tuning on actual monitoring data rather than guesswork
|
|
182
|
+
3. **Environment Isolation**: Use different connection configurations for dev/test/production environments
|
|
183
|
+
4. **Reserve Capacity**: Reserve 20% connection capacity for burst traffic
|
|
184
|
+
5. **Regular Checks**: Regularly check connection pool status to identify potential issues early
|
|
185
|
+
|
|
186
|
+
## Summary
|
|
187
|
+
|
|
188
|
+
The unified connection pool architecture simplifies configuration and management. Through proper parameter settings, it can effectively support various GraphQL operation modes. The key is to tune based on actual monitoring data to ensure a balance between resource efficiency and performance.
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
FROM node:18-alpine
|
|
2
|
+
|
|
3
|
+
WORKDIR /app
|
|
4
|
+
|
|
5
|
+
# Install pnpm
|
|
6
|
+
RUN npm install -g pnpm
|
|
7
|
+
|
|
8
|
+
# Copy dependency files
|
|
9
|
+
COPY package.json pnpm-lock.yaml* ./
|
|
10
|
+
|
|
11
|
+
# Install dependencies
|
|
12
|
+
RUN pnpm install --frozen-lockfile
|
|
13
|
+
|
|
14
|
+
# Copy source code
|
|
15
|
+
COPY . .
|
|
16
|
+
|
|
17
|
+
# Build project
|
|
18
|
+
RUN pnpm build
|
|
19
|
+
|
|
20
|
+
# Create non-root user
|
|
21
|
+
RUN addgroup -g 1001 -S nodejs
|
|
22
|
+
RUN adduser -S nodejs -u 1001
|
|
23
|
+
|
|
24
|
+
# Set user
|
|
25
|
+
USER nodejs
|
|
26
|
+
|
|
27
|
+
# Expose port
|
|
28
|
+
EXPOSE 4000
|
|
29
|
+
|
|
30
|
+
# Start application (can use CLI or direct start)
|
|
31
|
+
# Start using CLI method
|
|
32
|
+
CMD ["node", "dist/cli.js", "start"]
|
|
33
|
+
|
|
34
|
+
# Or start directly (optional)
|
|
35
|
+
# CMD ["pnpm", "start"]
|
package/LICENSE
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB Corporation Ab.
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Obelisk Labs
|
|
11
|
+
|
|
12
|
+
Licensed Work: Dubhe
|
|
13
|
+
The Licensed Work is (c) 2023 Obelisk Labs
|
|
14
|
+
|
|
15
|
+
-----------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
Terms
|
|
18
|
+
|
|
19
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
20
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
21
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
22
|
+
production use.
|
|
23
|
+
|
|
24
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
25
|
+
available distribution of a specific version of the Licensed Work under this
|
|
26
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
27
|
+
the terms of the Change License, and the rights granted in the paragraph
|
|
28
|
+
above terminate.
|
|
29
|
+
|
|
30
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
31
|
+
currently in effect as described in this License, you must purchase a
|
|
32
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
33
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
34
|
+
|
|
35
|
+
All copies of the original and modified Licensed Work, and derivative works
|
|
36
|
+
of the Licensed Work, are subject to this License. This License applies
|
|
37
|
+
separately for each version of the Licensed Work and the Change Date may vary
|
|
38
|
+
for each version of the Licensed Work released by Licensor.
|
|
39
|
+
|
|
40
|
+
You must conspicuously display this License on each original or modified copy
|
|
41
|
+
of the Licensed Work. If you receive the Licensed Work in original or
|
|
42
|
+
modified form from a third party, the terms and conditions set forth in this
|
|
43
|
+
License apply to your use of that work.
|
|
44
|
+
|
|
45
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
46
|
+
terminate your rights under this License for the current and all other
|
|
47
|
+
versions of the Licensed Work.
|
|
48
|
+
|
|
49
|
+
This License does not grant you any right in any trademark or logo of
|
|
50
|
+
Licensor or its affiliates (provided that you may use a trademark or logo of
|
|
51
|
+
Licensor as expressly required by this License).
|
|
52
|
+
|
|
53
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
|
54
|
+
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
|
57
|
+
TITLE.
|
|
58
|
+
|
|
59
|
+
MariaDB hereby grants you permission to use this License’s text to license
|
|
60
|
+
your works, and to refer to it using the trademark "Business Source License",
|
|
61
|
+
as long as you comply with the Covenants of Licensor below.
|
|
62
|
+
|
|
63
|
+
-----------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
Covenants of Licensor
|
|
66
|
+
|
|
67
|
+
In consideration of the right to use this License’s text and the "Business
|
|
68
|
+
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
|
69
|
+
other recipients of the licensed work to be provided by Licensor:
|
|
70
|
+
|
|
71
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
|
72
|
+
or a license that is compatible with GPL Version 2.0 or a later version,
|
|
73
|
+
where "compatible" means that software provided under the Change License can
|
|
74
|
+
be included in a program with software provided under GPL Version 2.0 or a
|
|
75
|
+
later version. Licensor may specify additional Change Licenses without
|
|
76
|
+
limitation.
|
|
77
|
+
|
|
78
|
+
2. To either: (a) specify an additional grant of rights to use that does not
|
|
79
|
+
impose any additional restriction on the right granted in this License, as
|
|
80
|
+
the Additional Use Grant; or (b) insert the text "None".
|
|
81
|
+
|
|
82
|
+
3. To specify a Change Date.
|
|
83
|
+
|
|
84
|
+
4. Not to modify this License in any other way.
|
|
85
|
+
|
|
86
|
+
-----------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
Notice
|
|
89
|
+
|
|
90
|
+
The Business Source License (this document, or the "License") is not an Open
|
|
91
|
+
Source license. However, the Licensed Work will eventually be made available
|
|
92
|
+
under an Open Source License, as stated in this License.
|