Skip to content

VBMAN Multiprocessor Example

Overview

This example demonstrates how to implement multiprocessing using the VBMAN framework, improving application performance and stability by distributing business logic across different processes.

Project Structure

Multiprocessor/
  ├── Form1.frm           # Main form, main process code
  ├── VBMAN_DEMO.vbp     # Main process project file
  └── sub/               # Subprocess code
      ├── bUsers.cls    # User business logic class
      └── VBMANControllers.vbp # Subprocess project file

Core Code Analysis

1. Main Process Code (Form1.frm)

vb
Dim HttpServer As New cHttpServer

Private Sub Form_Load()
    With HttpServer
        'Register subprocess user controller
        .Router.Reg "Users", New VBMANControllers.bUsers
        
        'Configure API routes
        .Router.Add "/api/users/list", "Users@List"
        
        'Start server
        .Start 80
    End With
    
    'Open browser to visit example
    Shell "explorer.exe http://127.0.0.1:80/api/users/list"
End Sub

2. User Business Class (bUsers.cls)

vb
'User business logic class, executed in subprocess
Option Explicit

Public Sub List(ctx As cHttpServerContext)
    'Create mock user data
    With ctx.Response.NewJson
        .Items.Add GetUser(1, "John", 25)
        .Items.Add GetUser(2, "Mike", 30)
        .Items.Add GetUser(3, "David", 28)
    End With
End Sub

Private Function GetUser(id As Long, name As String, age As Long) As Object
    With VBMAN.Json.NewJson
        .Item("id") = id
        .Item("name") = name
        .Item("age") = age
        Set GetUser = .Item
    End With
End Function

Feature Description

  1. Multiprocess Architecture

    • Main process handles request distribution
    • Subprocesses handle specific business logic
    • Inter-process communication
    • Load balancing
  2. Business Processing

    • Independent business modules
    • Fault isolation
    • Performance optimization
    • Resource management
  3. Process Management

    • Process creation
    • Process monitoring
    • Process restart
    • Resource recovery

Technical Points

  1. Inter-Process Communication (IPC)
  2. Request distribution mechanism
  3. Subprocess management
  4. Error handling mechanism

Use Cases

  1. High-concurrency web services
  2. Large-scale data processing
  3. Distributed computing
  4. CPU-intensive tasks

Extension Suggestions

  1. Add process pool management
  2. Implement dynamic scaling
  3. Add process monitoring
  4. Optimize process communication
  5. Add failover support

Base on VB6 component release