Top Banner
Et si on recodait Google en Python ? PyCon-FR 2016 [email protected]
47

PyCon FR 2016 - Et si on recodait Google en Python ?

Jan 17, 2017

Download

Engineering

Sylvain Zimmer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PyCon FR 2016 - Et si on recodait Google en Python ?

Et si on recodait Google en Python ?

PyCon-FR 2016

[email protected]

Page 2: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 3: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 4: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 5: PyCon FR 2016 - Et si on recodait Google en Python ?

transparence

reproductibilité

Page 6: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 7: PyCon FR 2016 - Et si on recodait Google en Python ?

https://uidemo.commonsearch.org

Page 8: PyCon FR 2016 - Et si on recodait Google en Python ?

https://explain.commonsearch.org/?q=python&g=en

Page 9: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 10: PyCon FR 2016 - Et si on recodait Google en Python ?

Google's early Python code

https://www.quora.com/Why-did-Google-move-from-Python-to-C++-for-use-in-its-crawler

Python (1.2 IIRC) would occasionally just core dump while running the crawler. It was completely stock, no C++ modules compiled in or dynamically

linked, just bog standard.

[...] no unit tests, and its "system tests" were minimal at best, absent at worst.

[...] there was originally some controversy about the switch. However, when the new C++ system was turned on and used fewer machines to crawl 5x

faster with higher reliability, the practical question was settled.

Python was "abandoned" from the core search stack around 2000.

Page 11: PyCon FR 2016 - Et si on recodait Google en Python ?

Qu'est-ce qui a changé depuis ?

• Stabilité & écosystème

• Librairies performantes en C / Cython

• Evolution des bottlenecks

• PyPy?

Page 12: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 13: PyCon FR 2016 - Et si on recodait Google en Python ?

http://infolab.stanford.edu/~backrub/google.htmlThe Anatomy of a Large-Scale Hypertextual Web Search Engine (1998)

Crawler

Parser

Index

SearcherRanker

Page 14: PyCon FR 2016 - Et si on recodait Google en Python ?

Crawler

Page 15: PyCon FR 2016 - Et si on recodait Google en Python ?

http://scrapy.org

Page 16: PyCon FR 2016 - Et si on recodait Google en Python ?

http://github.com/cocrawler/cocrawler

Page 17: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 18: PyCon FR 2016 - Et si on recodait Google en Python ?

http://commoncrawl.org

Page 19: PyCon FR 2016 - Et si on recodait Google en Python ?

Parser

Page 20: PyCon FR 2016 - Et si on recodait Google en Python ?

HTML parsers

• BeautifulSoup & derivés.

• lxml

• html5lib

• Gumbo!

Page 21: PyCon FR 2016 - Et si on recodait Google en Python ?

https://github.com/google/gumbo-parser

Page 22: PyCon FR 2016 - Et si on recodait Google en Python ?

Extensions C en Python

Mémoire gérée par PythonMémoire gérée par l'extension C

PyObject

ctypes

Page 23: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 24: PyCon FR 2016 - Et si on recodait Google en Python ?

Cython!

• Faire le gros du travail en C

• Eviter la conversion de données au maximum

• Générer une extension C pour Python facilement

Page 25: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 26: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 27: PyCon FR 2016 - Et si on recodait Google en Python ?

https://github.com/sylvinus/cython-simple-examples

Page 28: PyCon FR 2016 - Et si on recodait Google en Python ?

Gumbocy

• HTML envoyé au C en UTF-8, sans conversion

• Parcours de l'arbre en Cython

• Gestion de la visibilité & du boilerplate

• Attributs & tags ignorables, ...

https://github.com/commonsearch/gumbocy

Page 29: PyCon FR 2016 - Et si on recodait Google en Python ?

https://github.com/commonsearch/urlparse4

Page 30: PyCon FR 2016 - Et si on recodait Google en Python ?

Autres analyses

• Détection de langue : cld2

• Détection charset : cchardet + metatags/headers

• Cleaning titres & metadata

Page 31: PyCon FR 2016 - Et si on recodait Google en Python ?

Index

Page 32: PyCon FR 2016 - Et si on recodait Google en Python ?

https://pypi.python.org/pypi/Whoosh/

Page 33: PyCon FR 2016 - Et si on recodait Google en Python ?

http://lucene.apache.org/

Page 34: PyCon FR 2016 - Et si on recodait Google en Python ?

https://www.elastic.co

Page 35: PyCon FR 2016 - Et si on recodait Google en Python ?

Ranker

Page 36: PyCon FR 2016 - Et si on recodait Google en Python ?

Formule du ranking

rank = f( static_score , dynamic_score( query ) )

Alexa DMOZ

Blacklists PageRank

...

ElasticSearch & Lucene TF-IDF BM25

Page 37: PyCon FR 2016 - Et si on recodait Google en Python ?
Page 38: PyCon FR 2016 - Et si on recodait Google en Python ?

https://about.commonsearch.org/developer/get-started

Page 39: PyCon FR 2016 - Et si on recodait Google en Python ?

Searcher

Page 40: PyCon FR 2016 - Et si on recodait Google en Python ?

Go version: https://github.com/commonsearch/cosr-front

https://github.com/commonsearch/cosr-back/blob/master/cosrlib/searcher.py

Page 41: PyCon FR 2016 - Et si on recodait Google en Python ?

Frontend

Page 42: PyCon FR 2016 - Et si on recodait Google en Python ?

https://uidemo.commonsearch.org

Page 43: PyCon FR 2016 - Et si on recodait Google en Python ?

http://infolab.stanford.edu/~backrub/google.htmlThe Anatomy of a Large-Scale Hypertextual Web Search Engine (1998)

Crawler

Parser

Index

SearcherRanker

Page 44: PyCon FR 2016 - Et si on recodait Google en Python ?

Qu'est-ce qui manque ?

Page 45: PyCon FR 2016 - Et si on recodait Google en Python ?

Architecture• 2-pass search (host clustering, result diversity)

• Indexation continue

• Infoboxes

• Pubs

• Verticaux (images, vidéos, news, science, ...)

• ...

Page 46: PyCon FR 2016 - Et si on recodait Google en Python ?

Encore plus de funSpam / Relevance

Sustainability

Outreach

API

...

Page 47: PyCon FR 2016 - Et si on recodait Google en Python ?

Ca vous tente?https://about.commonsearch.org/contributing

https://github.com/commonsearch [email protected]

slack.commonsearch.org