Jianbing Fang
2020.01.15
Chaos...
// recommendation
GiveMeTheFuckingResultsNow();
Retrieval
Ranking
// retrieval stage
Retrieve();
// ranking stage
Rank();
Retrieval
Ranking
// retrieval stage
for (auto strategy : retrieval.GetStrategies()) {
strategy.Run();
}
// many dirty work here, like context switch...
// ranking stage
for (auto processor : ranking.GetProcessors()) {
processor.Apply();
}
Retrieval
Ranking
Pre-Stra.
Post-Stra.
// retrieval stage
for (auto strategy : retrieval.GetStrategies()) {
for (auto processor : strategy.GetPreProcessors()) {
processor.Apply1();
}
strategy.Run();
for (auto processor : strategy.GetPostProcessors()) {
processor.Apply1();
}
}
// ranking stage
for (auto processor : ranking.GetProcessors()) {
processor.Apply2();
}
Retrieval
Ranking
Pre-Stra.
Post-Stra.
Final-Stra.
// retrieval stage
for (auto strategy : retrieval.GetStrategies()) {
for (auto processor : strategy.GetPreProcessors()) {
processor.Apply1();
}
strategy.Run();
for (auto processor : strategy.GetPostProcessors()) {
processor.Apply1();
}
}
for (auto processor : retrieval.GetFinalProcessors()) {
processor.Apply1();
}
// ranking stage
for (auto processor : ranking.GetProcessors()) {
processor.Apply2();
}
O(n)
Pipeline
Pipeline
// the core of Common Leaf framework
for (auto pipeline : GetPipelines()) {
for (auto processor : pipeline.GetProcessors()) {
processor.Run();
}
}
O(1)
"All problems in computer science can be solved by another level of indirection."
JSON Config
C++ Program
JSON Config
C++ Program
DSL
from dragonfly.common_leaf_dsl import LeafService, LeafFlow, IndexSource
# some config definitions here...
logical_flow = LeafFlow(name = "default")
logical_flow.retrieve_by_local_index(query) \
.filter_by_browse_set() \
.get_abtest_params(ab_config) \
.limit(3000) \
.common_predict(predict_config) \
.ranking_by_lua(ranking_config) \
.variant(variant_config) \
.limit(20) \
.leaf_show(leaf_show_config)
service = LeafService(service_name = "grpc_XxxCommonLeaf", index_source = IndexSource.LOCAL)
service.add_leaf_flows(leaf_flows = [logical_flow], request_type = "default") \
.build()