1- // ecosystem.config.js
2- // PM2 Configuration for Address Validation Service
3-
41module . exports = {
52 apps : [
63 {
74 name : 'address-validation-service' ,
85 script : 'dist/server.js' ,
9-
10- // Cluster mode with automatic CPU core detection
11- exec_mode : 'cluster' ,
12- instances : 'max' , // Use all available CPU cores
13-
14- // Memory management
15- max_memory_restart : '512M' , // Restart if memory exceeds 512MB
16-
17- // Restart behavior
6+ exec_mode : 'fork' ,
7+ max_memory_restart : '138M' ,
188 autorestart : true ,
19- watch : false , // Don't watch in production
9+ watch : false ,
2010 max_restarts : 10 ,
21- min_uptime : '20s' , // App must run for 20s to be considered started
11+ min_uptime : '20s' ,
12+ restart_delay : 4000 ,
2213
23- // Logging
2414 error_file : './logs/error.log' ,
2515 out_file : './logs/out.log' ,
2616 log_file : './logs/combined.log' ,
27- time : true , // Add timestamps to logs
17+ time : true ,
2818 merge_logs : true ,
2919 log_date_format : 'YYYY-MM-DD HH:mm:ss Z' ,
3020
31- // Environment variables
3221 env : {
3322 NODE_ENV : 'production' ,
3423 PORT : 3715 ,
@@ -39,27 +28,13 @@ module.exports = {
3928 LOG_LEVEL : 'debug' ,
4029 } ,
4130
42- // Graceful shutdown
43- kill_timeout : 5000 , // 5 seconds to gracefully shutdown
44- listen_timeout : 3000 , // 3 seconds to be ready
45-
46- // Performance optimizations
47- node_args : [
48- '--max-old-space-size=512' , // Limit heap to 512MB
49- '--optimize-for-size' , // Optimize for memory usage
50- '--gc-interval=100' , // More frequent garbage collection
51- ] . join ( ' ' ) ,
52-
53- // Health check
54- cron_restart : '0 3 * * *' , // Daily restart at 3 AM to prevent memory leaks
55-
56- // Monitoring
57- instance_var : 'INSTANCE_ID' , // Differentiate between cluster instances
31+ kill_timeout : 5000 ,
32+ listen_timeout : 3000 ,
5833
59- // Zero-downtime reload
60- wait_ready : true , // Wait for ready signal
34+ node_args : [ '--max-old-space-size=110' , '--optimize-for-size' , '--gc-interval=100' ] . join ( ' ' ) ,
6135
62- // Dependencies
36+ cron_restart : '0 3 * * *' ,
37+ wait_ready : true ,
6338 post_update : [ 'npm install' , 'npm run build' ] ,
6439 } ,
6540 ] ,
0 commit comments