4. NoSQL
Not Only SQL
• Plusieurs catégories de databases NoSQL
• Document Store (MongoDB)
• Graph (Neo4j)
• Key-Value Store (Redis, Memcached, Cassandra, BigTable)
• ...
5. Pourquoi NoSQL ?
• Performance !!!
• Données non structurées
• Utilisation sur un hardware aux ressources limitées
7. MongoDB ?
[52541.307871] [<ffffffff810cc981>] ? handle_mm_fault+0x27a/0x80f
[52541.307886] [<ffffffff812fe6b6>] ? do_page_fault+0x2e0/0x2fc
[52541.307897] [<ffffffff812fc555>] ? page_fault+0x25/0x30
[52541.307907] Disabling lock debugging due to kernel taint
[52541.307918] BUG: Bad page state in process mongod pfn:3d7c2
[52541.307927] page:ffffea0000d73270 flags:0100000000100068 count:1
mapcount:1 mapping:ffff88006036e621 index:7f82c1fea
[52541.307940] Pid: 1326, comm: mongod Tainted: G B 2.6.32-5-amd64
#1
[52541.307948] Call Trace:
[52541.307959] [<ffffffff810b7a11>] ? bad_page+0x116/0x129
[52541.307968] [<ffffffff810b9b2e>] ? get_page_from_freelist+0x4fd/0x760
La VM crash.....
[52541.307983] [<ffffffff81153037>] ? cap_file_mprotect+0x0/0x3
[52541.307995] [<ffffffff8100e242>] ? check_events+0x12/0x20
8. Redis, notre sauveur
• Key-Value store
• Ecrit en C
• Très performant
• En mémoire
• With data structure:
• Strings, Hashes, Lists, Sets and Sorted Sets
9. Ce que nous avons appris
Une BD en mémoire vive ? « J’ai trop de données !!! »
L’oeuvre complète de Shakespeare représente 5.5Mb, et compressée 2Mb.
NewsInApp.io ➠ 900 Mb réparti sur 3 bases de données Redis.
Mythe « La mémoire vive est peu onéreuse »
Mais, la quantité de mémoire est le principal critère de coût chez les hébergeurs
Amazon EC2: Small Instance = 1.7 Gb, Medium Instance = 3.75...
Prgmr: 1 Gb = $192 par an, 2 Gb = $345 et 4 Gb = $652
Ne conserver que les données opérationnelles (utilisées)
Nous ne conversons les news qu’au maximum 20 jours.
10. Mini moteur de recherche
Démonstration de l’utilisation de
Redis avec Python
11. Metaphone
• Metaphone is a phonetic algorithm, an algorithm for indexing words by their English pronunciation
See http://en.wikipedia.org/wiki/Metaphone
• The Double Metaphone phonetic encoding algorithm is the second generation of this algorithm
• Examples:
Python ➠ P0N PTN
Pythen ➠ P0N PTN
Pithon ➠ P0N PTN
Piton ➠ PTN
13. Indexation des topics
topic 3000 topic 1782 topic 1486
keywords «Johnny Depp» keywords «John Seymour» keywords «Wino»
metaphones des keywords metaphones des keywords metaphones des keywords
Johnny ➠ JN, AN John ➠ JN, AN Wino ➠ AN, FN
Depp ➠ TP Seymour ➠ SMR
topic 1737
keywords «Debbie Macomber»
metaphones des keywords
Debbie ➠ TP
Macomber ➠ MKMPR
14. Indexation: Metaphone et Redis
Chaque metaphone est une clé dont la valeur est un SET (liste sans doublons). Ce SET contient tous les
topics utilisant ce metaphone
JN ➠ 3000, 1782 AN ➠ 3000, 1782, 1486 TP ➠ 3000, 1737
15. Recherche de «Johnny Depp»
• Chaque metaphone est une clé dont la valeur est un SET (liste sans doublons). Ce SET contient tous les
topics utilisant ce metaphone
JN ➠ 3000, 1782 AN ➠ 3000, 1782, 1486 TP ➠ 3000, 1737
• Un peu de magie Redis avec la commande SINTER (Intersection de SET)
SINTER( JN, AN, TP) ➠ 3000
Intersection de trois listes (sets)
16. Un exemple de recherche
Que donnerait cette méthode avec le keyword « DEPP » (Metaphone: TP) ?
• Debbie Macomber
• Johnny Depp
• Metaphysia: Earth in Deep Shift
• ...
17. Levenshtein distance
• Il s’agit d’une métrique de « distance » entre deux mots.
http://en.wikipedia.org/wiki/Levenshtein_distance
• Implementation Python: python-Levenshtein
22. • Redis est ultra performant et simple à maitriser.
• Utilisation de Redis avec Python :)))))
didier.rano@gmail.com
@newsinapp
Vous êtes les bienvenus pour l’alpha de NewsInApp.io