HIT Lookup Strategies
CV has two strategies to lookup HITs in HitType. This is due to major performance impact of the old method we used.
The old method:
Search for 'ASSIGNABLE' HIT,
Filter HITs by their assignment:
AND NOT EXISTS (SELECT 1 FROM assignment a WHERE a.hit_id = h.id AND a.worker_id = ? AND a.assignment_status IN ('SKIPPED', 'ACCEPTED', 'SUBMITTED', 'APPROVED', 'REJECTED'))
AND NOT EXISTS (SELECT 1 FROM assignment a WHERE a.hit_id = h.id AND a.worker_id = ? AND a.assignment_status IN ('RETURNED', 'ABANDONED') AND a.deadline > ?)
AND (SELECT COUNT(id) FROM assignment a WHERE a.hit_id = h.id AND a.assignment_status IN ('ACCEPTED', 'SUBMITTED', 'APPROVED', 'REJECTED')) < h.max_assignments
Sort by:
- sort_order (calculated by HIT Comparator, obsolete as Comparator is used on WF side).
- priority (obsolete but still in database)
- number of assignments submitted for HIT. The more assignments are submitted, the more likely HIT will appear in result set.
- Limit 20
CV is taking 20 HITs from database and takes random HIT. This is to prevent workers to preview/accept the same HIT.
Old method has been extracted as lookup strategy: AvailableHitsSlowOrderedLookupStrategy.
The new strategy — AvailableHitsFastNonOrderedLookupStrategy:
HIT has new column, prioritized, indicating that HIT has submitted assignments.
- Query 1
- Search for 'ASSIGNABLE' HIT
- Filter HITs by their assignment (same as in slow strategy)
- Filter by prioritized = true
- Limit 20
- UNION
- Query 2
- Search for 'ASSIGNABLE' HIT
- Filter HITs by their assignment (same as in slow strategy)
- Filter by prioritized = false
- Limit 20
- CV takes 40 HITs
- Sorts result set so prioritized HITs are in the beginning of the list
- Takes first 20 HITs from the list
- Returns random HIT from the result of p. 6.
In case prioritized is indexed, the AvailableHitsFastNonOrderedLookupStrategy is faster than AvailableHitsSlowOrderedLookupStrategy by a factor of 10 — 1000.
To switch to AvailableHitsFastNonOrderedLookupStrategy use following JNDI setting:
<Environment name="cv/useFastHitLookupStrategy" value="true" type="java.lang.Boolean"/>