cHttpServerStatistics Performance Statistics
Overview
cHttpServerStatistics is the server-level performance statistics container for HttpServer, implementing zero-overhead increment through Public Long fields — no Dictionary lookups, no Property calls, suitable for high-frequency hot path instrumentation.
The globally unique instance is created in cHttpServer.Class_Initialize and accessible via two paths:
' Method 1: Via Server object (available throughout server lifecycle)
Server.Statistics.TotalRequests
' Method 2: Via request context (more natural in controllers/middleware)
ctx.Statistics.TotalRequestsBoth point to the same object instance. ctx.Statistics only performs a Set .Statistics = Statistics reference assignment in ProcessHttpRequest, with no additional overhead.
Lifecycle Note: Statistics is a server-level singleton. Neither
cHttpServerContext.ReleaseRequestnorReleasereleases this reference.
Field Overview
Request Statistics
| Field | Type | Description |
|---|---|---|
TotalRequests | Long | Cumulative total requests (including normal and exceptional) |
GetRequests | Long | GET request count |
PostRequests | Long | POST request count |
PutRequests | Long | PUT request count |
DeleteRequests | Long | DELETE request count |
OptionsRequests | Long | OPTIONS request count |
HeadRequests | Long | HEAD request count |
PatchRequests | Long | PATCH request count |
OtherRequests | Long | Request count for methods other than above |
Method classification is done internally by IncrementByMethod, based on cHttpServerRequest.EnumRequestMethod enum values:
| Enum Value | Constant Name | Incremented Field |
|---|---|---|
| 1 | ReqPost | PostRequests |
| 2 | ReqGet | GetRequests |
| 3 | ReqPut | PutRequests |
| 4 | ReqDelete | DeleteRequests |
| 5 | ReqOptions | OptionsRequests |
| 6 | Head | HeadRequests |
| 7 | Patch | PatchRequests |
| Other | — | OtherRequests |
Status Code Statistics
| Field | Type | Description |
|---|---|---|
Status1xx | Long | 1xx response count (Informational) |
Status2xx | Long | 2xx response count (Success) |
Status3xx | Long | 3xx response count (Redirection) |
Status4xx | Long | 4xx response count (Client Error) |
Status5xx | Long | 5xx response count (Server Error) |
Status code range classification is done internally by IncrementByStatusCode, grouping by the hundreds digit of the actual status code.
Prerequisite:
cHttpServerResponse.StatusCodefield is assigned inSendHeader. If the response doesn't reachSendHeader(e.g., connection already closed), StatusCode is 0 and not counted in any range.
Connection Statistics
| Field | Type | Description |
|---|---|---|
TotalConnectionsAccepted | Long | Cumulative total connections accepted |
RejectedConnections | Long | Connections rejected due to MaxConnections limit |
PeakConnections | Long | Peak concurrent connections |
IdleConnectionsCleaned | Long | Connections cleaned by CleanupIdleConnections due to idle timeout |
Error Statistics
| Field | Type | Description |
|---|---|---|
RequestErrors | Long | Request processing exceptions (EH path in ProcessHttpRequest) |
RequestSizeRejected | Long | 413 Payload Too Large count |
SSEEntryErrors | Long | SSE Entry failure count (reserved field, not instrumented in current version) |
Traffic Statistics
| Field | Type | Description |
|---|---|---|
TotalBytesReceived | Long | Cumulative bytes received |
TotalBytesSent | Long | Cumulative bytes sent |
Current Status: Fields are reserved but not yet instrumented in
cClientCallback.OnDataArrivalandcHttpServerResponse.SendBodyByte. Precise byte counting in high-traffic scenarios may impact performance; enable as needed.
SSE Statistics
| Field | Type | Description |
|---|---|---|
SSEConnectionsAccepted | Long | Total SSE connections |
Session Statistics
| Field | Type | Description |
|---|---|---|
TotalSessionsCreated | Long | Cumulative total sessions created (only valid sessions with Session.HasID) |
Time Statistics
| Field | Type | Description |
|---|---|---|
StartTime | Date | Server start time (assigned Now in Start method) |
Computed Properties
UptimeSeconds
Server uptime in seconds.
Public Property Get UptimeSeconds() As LongReturns 0 if StartTime = 0 (not started).
AverageQPS
Average requests per second.
Public Property Get AverageQPS() As DoubleCalculation: TotalRequests / UptimeSeconds. Returns 0 when uptime is 0.
Friend Methods
The following methods are for internal cHttpServer use; external code does not need to call them directly.
IncrementByMethod
Increment the corresponding counter by request method enum value.
Friend Sub IncrementByMethod(ByVal MethodValue As Long)See the enum value table in the "Request Statistics" section above for mapping.
IncrementByStatusCode
Increment the corresponding range counter by actual status code.
Friend Sub IncrementByStatusCode(ByVal StatusCode As Long)Divides StatusCode \ 100 to get the hundreds digit, mapping to Status1xx~Status5xx.
UpdatePeakConnections
Update peak connections (only updates when current value exceeds historical peak).
Friend Sub UpdatePeakConnections(ByVal CurrentCount As Long)Reset Method
Reset all statistics counters to 0, StartTime reset to Now.
Public Sub Reset()Example:
' Reset statistics daily at midnight
Server.Statistics.ResetInstrumentation Location Reference
| Trigger Location | Statistics Fields | Description |
|---|---|---|
ConnectionRequest event | TotalConnectionsAccepted, PeakConnections, RejectedConnections | On new connection |
Start method | StartTime = Now | Record time baseline on server start |
| 413 path (request body exceeded) | RequestSizeRejected | OnDataArrival detects limit exceeded |
| SSE Entry path | SSEConnectionsAccepted | When SSE long connection established |
After Router.Entry | TotalRequests, IncrementByMethod, IncrementByStatusCode | Statistics after routing completes |
Session.HasID is True | TotalSessionsCreated | When valid Session created |
| EH error handling path | RequestErrors, TotalRequests | Exceptions also counted in TotalRequests |
CleanupIdleConnections | IdleConnectionsCleaned | On timer or manual cleanup |
Usage Examples
Monitoring Endpoint
Expose a statistics API endpoint in a controller:
' GET /api/stats
Public Sub GetStats(ctx As cHttpServerContext)
Dim s As cHttpServerStatistics
Set s = ctx.Statistics
Dim result As New Scripting.Dictionary
' Request metrics
result("total_requests") = s.TotalRequests
result("get_requests") = s.GetRequests
result("post_requests") = s.PostRequests
' Status code distribution
result("status_2xx") = s.Status2xx
result("status_4xx") = s.Status4xx
result("status_5xx") = s.Status5xx
' Connection metrics
result("current_connections") = ctx.Server.Parent.ConnectionCount
result("peak_connections") = s.PeakConnections
result("rejected_connections") = s.RejectedConnections
' Performance metrics
result("uptime_seconds") = s.UptimeSeconds
result("average_qps") = s.AverageQPS
result("request_errors") = s.RequestErrors
ctx.Response.Json result, 0, "OK"
End SubError Rate Alerting
' Check error rate in middleware
Public Sub ErrorRateCheck(ctx As cHttpServerContext)
Dim s As cHttpServerStatistics
Set s = ctx.Statistics
If s.TotalRequests > 100 Then
Dim errorRate As Double
errorRate = (s.Status5xx + s.RequestErrors) / s.TotalRequests
If errorRate > 0.1 Then
' 5xx + exceptions exceed 10%, log alert
Call WriteAlertLog("Error rate too high: " & Format(errorRate, "0.00%"))
End If
End If
End SubRuntime Dashboard
Public Sub Dashboard(ctx As cHttpServerContext)
Dim s As cHttpServerStatistics
Set s = ctx.Statistics
Dim html As String
html = "<h1>Server Status</h1>"
html = html & "<p>Uptime: " & s.UptimeSeconds & " seconds</p>"
html = html & "<p>Total Requests: " & s.TotalRequests & "</p>"
html = html & "<p>Average QPS: " & Format(s.AverageQPS, "0.00") & "</p>"
html = html & "<p>Peak Connections: " & s.PeakConnections & "</p>"
ctx.Response.Html html
End SubLong Overflow Considerations
VB6 Long type is a 32-bit signed integer with an upper limit of 2,147,483,647.
| Scenario | QPS | Overflow Time |
|---|---|---|
| Low traffic | 10 | ~6.8 years |
| Medium traffic | 100 | ~249 days |
| High traffic | 1,000 | ~24.9 days |
| Very high traffic | 10,000 | ~2.5 days |
Recommendations:
- In high-traffic scenarios (QPS > 1000), periodically call
Resetor record a snapshot when approaching the threshold and then reset - When reading from the monitoring endpoint, first check if
TotalRequestsis approaching the limit, and proactively alert - For longer accumulation periods, maintain a
Doubletype accumulator externally, periodically reading increments fromTotalRequests
Dependencies
cHttpServer
│
├── Public Statistics As cHttpServerStatistics ← Server holds instance
│ ├── Public Long fields × 20+
│ ├── Property Get UptimeSeconds / AverageQPS
│ ├── Friend Sub IncrementByMethod / IncrementByStatusCode / UpdatePeakConnections
│ └── Public Sub Reset
│
└── ProcessHttpRequest
└── ctx.Statistics ──→ Same instance referencecHttpServerResponse adds Public StatusCode As Long field, assigned in SendHeader, providing data source for IncrementByStatusCode.
Last Updated: 2026-06-13