We solved almost this exact problem last year on FT 10.0. You need to tackle all three focus areas systematically to see real improvement.
Custom Sampling Plan Logic Optimization:
First, implement a cached sampling plan lookup table that refreshes hourly instead of calculating on every query. Create a materialized view or dedicated cache table:
CREATE TABLE sampling_cache AS
SELECT plan_id, lot_size_range, sampling_rate, last_updated
FROM sampling_plans
Update this during off-peak hours (2-4 AM) so real-time queries just read cached values.
SQL Query Optimization:
Your current query is missing critical indexes and pulling unnecessary data. Rewrite it to be more selective:
SELECT i.id, i.lot_id, sc.sampling_rate
FROM inspections i
INNER JOIN sampling_cache sc ON i.plan_id = sc.plan_id
WHERE i.status = 'pending' AND i.lot_size BETWEEN sc.lot_size_min AND sc.lot_size_max
Add composite indexes on (status, lot_size) and partition the inspections table by creation_date. Archive records older than 6 months to reduce table size from 2M to under 500K active records.
Batch Job Scheduling:
Adjust your scheduler based on production load patterns. Instead of fixed 5-minute intervals, implement dynamic scheduling:
- Peak hours (6 AM - 2 PM): Run every 10 minutes with batch size limit of 200 lots
- Normal hours (2 PM - 10 PM): Run every 7 minutes with batch size 300
- Off-peak (10 PM - 6 AM): Run every 15 minutes, no batch limit
Use batch commits for inspection assignments - group 50-100 assignments per transaction instead of individual commits. This reduced our processing time from 18 seconds per batch to 2-3 seconds.
Implement asynchronous inspection task creation using FT’s job queue system. When a large lot completes, queue the inspection assignment as a background job rather than blocking the completion transaction.
Results we achieved:
- Query time: 15s → 1.2s average
- Batch processing: 3-4 min → 30-45 seconds
- Queue backup: Eliminated during peak hours
- Operator wait time: 3-4 min → under 1 minute
The key is addressing all three areas together. Optimizing just the SQL won’t help much if your batch scheduling is still inefficient, and caching won’t matter if you’re still doing individual commits. Implement these changes in a test environment first and monitor with FT’s performance metrics dashboard.