doc/ffto_design.md
The Fast Forward Traffic Observer (FFTO) is a high-performance, non-intrusive monitoring subsystem for ProxySQL. It provides deep query-level observability for connections operating in "Fast Forward" (FF) mode. In this mode, ProxySQL acts as a transparent protocol-aware pipe, bypassing the heavy query processing engine to achieve maximum throughput and minimum latency. FFTO extracts metadata—such as SQL digests, execution latency, affected rows, and error codes—from the raw protocol stream.
stats_mysql_query_digest).The FFTO behavior is controlled by the following global configuration variables:
mysql-ffto_enabled: (Boolean) Enables or disables FFTO for MySQL connections.mysql-ffto_max_buffer_size: (Integer) The maximum payload size (in bytes) that the MySQL FFTO will attempt to buffer for a single packet. If exceeded, FFTO is disabled for that specific session.pgsql-ffto_enabled: (Boolean) Enables or disables FFTO for PostgreSQL connections.pgsql-ffto_max_buffer_size: (Integer) The maximum payload size (in bytes) that the PostgreSQL FFTO will attempt to buffer for a single packet. If exceeded, FFTO is disabled for that specific session.Defined in include/TrafficObserver.hpp. This interface decouples protocol-specific parsing from ProxySQL session management.
on_client_data(const char* buf, size_t len): Identifies queries, extracts SQL text, and parses prepared statement parameters.on_server_data(const char* buf, size_t len): Tracks result set headers, counts rows, and identifies command completion or error packets.on_close(): Ensures metrics are finalized and resources are released.MySQLFFTO)Implements the MySQL wire protocol (version 10) state machine.
IDLE, AWAITING_PREPARE_OK, AWAITING_RESPONSE, READING_COLUMNS, READING_ROWS.stmt_id to query templates captured during the PREPARE phase.PgSQLFFTO)Handles the message-oriented PostgreSQL protocol.
Query ('Q'), Parse ('P'), Bind ('B'), and Execute ('E') messages.CommandComplete ('C'), ReadyForQuery ('Z'), and ErrorResponse ('E').*-ffto_max_buffer_size threshold, the FFTO instance for that session is disabled (bypassed). This prevents excessive memory usage on connections transferring large BLOBs or large result sets.m_client_buffer, m_server_buffer) to reconstruct full protocol messages from fragmented network packets.Query_Processor cache and SpookyHash to avoid redundant hashing of identical query patterns, ensuring metric parity with standard query processing.MySQL_Session::handler() and PgSQL_Session::handler() within the FAST_FORWARD state.The following variables can be adjusted at runtime via the Admin interface:
-- Enable/Disable FFTO
UPDATE global_variables SET variable_value='true' WHERE variable_name='mysql-ffto_enabled';
UPDATE global_variables SET variable_value='true' WHERE variable_name='pgsql-ffto_enabled';
-- Set max buffer size (default 1MB)
UPDATE global_variables SET variable_value='2097152' WHERE variable_name='mysql-ffto_max_buffer_size';
LOAD MYSQL VARIABLES TO RUNTIME;
LOAD PGSQL VARIABLES TO RUNTIME;
To verify that FFTO is capturing traffic in Fast Forward mode:
debug logging or monitor the specific debug modules:
-- For MySQL
UPDATE global_variables SET variable_value=1 WHERE variable_name='mysql-debug';
-- For PostgreSQL
UPDATE global_variables SET variable_value=1 WHERE variable_name='pgsql-debug';
LOAD MYSQL VARIABLES TO RUNTIME;
LOAD PGSQL VARIABLES TO RUNTIME;
fast_forward=1).stats_mysql_query_digest or stats_pgsql_query_digest tables:
SELECT count_star, sum_time, digest_text FROM stats_mysql_query_digest;
COM_STMT_PREPARE and COM_STMT_EXECUTE, tracking statement IDs to their respective SQL text.Parse -> Bind -> Execute sequence by tracking Statement and Portal mappings.*-ffto_max_buffer_size threshold cause FFTO to be bypassed for that session.sum_rows_affected/sum_rows_sent are derived from CommandComplete tags and currently cover common commands (INSERT, UPDATE, DELETE, COPY, MERGE, SELECT, FETCH, MOVE).