Skip to content

Mongoose server Deployment Guide

Introduction

This document provides guidance on deploying Mongoose server in various environments. It covers deployment considerations, performance tuning, and best practices to ensure optimal operation of Mongoose server applications.

Deployment Models

Mongoose server can be deployed in several ways, depending on the requirements of your application:

Standalone Application

Mongoose server can be deployed as a standalone Java application. This is the simplest deployment model and is suitable for many use cases.

Configuration:

// Load configuration from a file
FluxtionServer server = FluxtionServer.bootServer(logRecordListener);

// Or programmatically
AppConfig appConfig = new AppConfig();
// Configure appConfig
FluxtionServer server = FluxtionServer.bootServer(appConfig, logRecordListener);

Embedded in Another Application

Mongoose server can be embedded within another Java application, such as a Spring Boot application or a web server.

Configuration:

// Create and configure the server
AppConfig appConfig = new AppConfig();
// Configure appConfig
FluxtionServer server = new FluxtionServer(appConfig);

// Register components
server.registerEventSource("source1", eventSource);
server.addEventProcessor("processor1", "group1", idleStrategy, () -> eventProcessor);

// Initialize and start
server.init();
server.start();

Containerized Deployment

Mongoose server can be deployed in containers such as Docker, which provides isolation and portability.

Dockerfile Example:

FROM openjdk:11-jre-slim

WORKDIR /app

COPY target/fluxtion-server.jar /app/
COPY config/server-config.yaml /app/config/

ENV JAVA_OPTS="-Xmx2g -Xms1g"
ENV CONFIG_FILE="/app/config/server-config.yaml"

CMD ["java", "-jar", "fluxtion-server.jar", "-Dfluxtionserver.config.file=${CONFIG_FILE}"]

Cloud Deployment

Mongoose server can be deployed to cloud environments such as AWS, Azure, or Google Cloud Platform.

Considerations:

  • Use managed services for monitoring and logging
  • Configure auto-scaling based on load
  • Use cloud-native storage for persistence
  • Implement proper security measures

Performance Considerations

Memory Configuration

Proper memory configuration is essential for optimal performance:

-Xmx<size>  # Maximum heap size
-Xms<size>  # Initial heap size
-XX:MaxMetaspaceSize=<size>  # Maximum metaspace size

Recommended settings: - Set -Xms and -Xmx to the same value to avoid heap resizing - Monitor memory usage and adjust as needed - Consider using G1GC for large heaps: -XX:+UseG1GC

Thread Configuration

Mongoose server uses a threading model based on agents. Configure threads appropriately:

threadConfig:
  - name: "default"
    idleStrategy: "BusySpin"
  - name: "lowLatency"
    idleStrategy: "BusySpin"
  - name: "highThroughput"
    idleStrategy: "BackOff"

Considerations: - Use BusySpin for low-latency requirements - Use BackOff for high-throughput scenarios - Balance the number of threads with available CPU cores

Queue Sizing

Configure queue sizes based on expected load:

// In EventFlowManager.java
new ManyToOneConcurrentArrayQueue<T>(queueSize);

Recommendations: - Start with a queue size of 1024 or 2048 - Monitor queue overflow and adjust as needed - Consider using different queue sizes for different event types

High Availability

Clustering

For high availability, deploy multiple instances of Mongoose server in a cluster:

  1. Active-Passive: One active instance with one or more passive instances ready to take over
  2. Active-Active: Multiple active instances sharing the load

State Replication

If your application maintains state, consider state replication strategies:

  1. Shared Database: Store state in a shared database
  2. Event Sourcing: Rebuild state from event logs
  3. State Snapshots: Periodically save and restore state snapshots

Failover

Implement failover mechanisms to handle instance failures:

  1. Health Checks: Regular health checks to detect failures
  2. Automatic Restart: Restart failed instances automatically
  3. Load Balancing: Distribute load across healthy instances

Monitoring and Observability

Metrics Collection

Collect metrics to monitor the health and performance of your Mongoose server:

  1. JVM Metrics: Heap usage, GC activity, thread count
  2. Application Metrics: Event throughput, processing latency, queue sizes
  3. System Metrics: CPU usage, memory usage, disk I/O, network I/O

Logging

Configure appropriate logging to aid in troubleshooting:

// Set log level for event processors
eventProcessor.setAuditLogLevel(EventLogControlEvent.LogLevel.INFO);

Recommendations: - Use structured logging for easier parsing - Configure appropriate log levels for different components - Rotate logs to manage disk space

Distributed Tracing

Implement distributed tracing to track events across components:

  1. Trace IDs: Add trace IDs to events
  2. Span IDs: Create spans for different processing stages
  3. Visualization: Use tools like Jaeger or Zipkin to visualize traces

Security Considerations

Authentication and Authorization

Implement proper authentication and authorization:

  1. API Security: Secure admin APIs with authentication
  2. Role-Based Access: Restrict access based on roles
  3. Secure Communication: Use TLS for communication between components

Data Protection

Protect sensitive data:

  1. Encryption: Encrypt sensitive data at rest and in transit
  2. Data Masking: Mask sensitive data in logs
  3. Access Control: Restrict access to sensitive data

Network Security

Secure the network:

  1. Firewalls: Restrict network access
  2. VPNs: Use VPNs for secure communication
  3. Network Segmentation: Isolate components in different network segments

Configuration Management

Configuration Files

Manage configuration files effectively:

  1. Version Control: Store configuration files in version control
  2. Environment-Specific Configs: Use different configurations for different environments
  3. Configuration Validation: Validate configuration before deployment

Dynamic Configuration

Consider dynamic configuration for runtime changes:

// Update configuration at runtime
ConfigUpdate configUpdate = new ConfigUpdate();
configUpdate.setConfigMap(newConfigMap);
eventProcessor.onEvent(configUpdate);

Deployment Checklist

Before deploying Mongoose server to production, ensure:

  1. Performance Testing: Test performance under expected load
  2. Security Review: Review security measures
  3. Monitoring Setup: Set up monitoring and alerting
  4. Backup Strategy: Implement backup and recovery procedures
  5. Documentation: Document deployment procedures and configurations
  6. Rollback Plan: Prepare a rollback plan in case of issues

Conclusion

Deploying Mongoose server requires careful consideration of various factors including performance, high availability, monitoring, and security. By following the guidelines in this document, you can ensure a successful deployment that meets your application's requirements.

Remember that deployment is not a one-time activity but an ongoing process. Continuously monitor, evaluate, and improve your deployment to maintain optimal performance and reliability.