The Evolution of Common Leaf

Jianbing Fang

2020.01.15

The Story

Chaos...

The Story

// recommendation
GiveMeTheFuckingResultsNow();

The Story

Retrieval

Ranking

The Story

// retrieval stage
Retrieve();

// ranking stage
Rank();

The Story

Retrieval

Ranking

The Story

// 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();
}

The Story

Retrieval

Ranking

Pre-Stra.

Post-Stra.

The Story

// 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();
}

The Story

Retrieval

Ranking

Pre-Stra.

Post-Stra.

Final-Stra.

The Story

// 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();
}

The Complexity of Leaf Framework

O(n)

Common Leaf

Pipeline

Pipeline

Finally

// the core of Common Leaf framework
for (auto pipeline : GetPipelines()) {
  for (auto processor : pipeline.GetProcessors()) {
    processor.Run();
  }
}

The Complexity of Leaf Framework

O(1)

Some Lessons

  • insight the original nature
  • embrace change
  • KEEP IT SIMPLE !!!

The End?

Maintainer

User

David John Wheeler said:

"All problems in computer science can be solved by another level of indirection."

Dragonfly

JSON Config

C++ Program

JSON Config

C++ Program

DSL

DSL Config

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()

Some Thoughts

  • maintenance vs performance
  • ease of use vs maintenance
  • transparency vs ease of use

Some Suggestions

  • naming! naming! naming!
  • spare more time on design
  • keep exploring

Thanks

Questions?

Made with Slides.com