Parsing and compressing the blockchain for the SteemWorld Web API...
After I've successfully downloaded all blocks and saved the transactions in a local relational database, now the fun part begins.
How it works
My goal is to have one self-refreshing (current) db on my server that will only contain the data of the past few days/weeks so that the indices won't get to large and therefore write operations will always be executed with maximum performance. When a client makes a request to receive the new mentions, followers, etc. for an account the server will search in the (current) db and return the rows instantly.
After thinking about it for some hours, I came to the conclusion that my server needs to create new databases automatically in a defined interval and move the old db to a backup directory periodically. As I'm working with SQLite this can be done in a much easier and faster way than by using MySQL. The script for parsing new blocks and handling/creating the backup dbs will be executed by a Cronjob on the server. The filename for each db in the backup path will contain information about the date range of the in there stored data so that the server does not need to walk through millions of rows to retrieve data for a specific day. That makes it possible to retrieve old account operations very fast as well.
I've much experience in professional database administration/development and have worked with different big vendors like Oracle, Informix, Sybase (ASA) and MySQL for many years. Nevertheless I decided to use a purely file-based type of database and SQLite seems to be the perfect choice for me here (MongoDB would also work and may be my second choice). That also enables me to attach external db files easily (for example from backup dir) to an existing connection of the main (current) db and join the data within one SELECT-Statement (or multiple UNION's as well).
Better Compression
Since I want to save as much disc space as possible, I've written an own compression algorithm for the operations. Some of you might know that the transactions consist of much redundant data that could be saved in a much better way than just putting the complete JSON into a column. As far as I know, @dan has done similiar optimizations for EOS recently. Before the data will get deflated, the property names in the JSON Object will be replaced by 'Property IDs' which are automatically being stored in kind of a 'JSON IDs table'.
In theory it's done
One thing I've learned on my journey as developer is the importance of spending time in planning and thinking about different scenarios that can occur in a production environment. I know that there will be coming a huge number of requests from SteemWorld and I want to be well prepared for that. In most cases making big changes to a running system later lead to more headaches and sometimes unforeseeable consequences.
If you don't see any changes coming to the SteemWorld currently it is because the main work happens in background on many pieces of paper ;) Since I'm currently receiving new ideas for the site nearly every day, I'm thinking about creating an extra post for ideas/feedback/bug tracking and adding a link to it on SteemWorld, so that others can see what is already planned.
Please be patient and keep in mind that this is all being developed by me alone. I know that there are still many nice features missing in the tool and I will continue to work on them as soon as the Web API is running stable. As mentioned before, my current step will enable me to realize many cool things like desktop notifications for mentions/followers, a fast overview for incoming delegations and SP ranks as it has been on steemwhales.com.
[DE]
Parsen und Komprimieren der Blockchain für die SteemWorld Web API...
Nachdem ich alle Blöcke erfolgreich heruntergeladen und die Transaktionen in einer lokalen relationalen Datenbank gespeichert habe, beginnt jetzt der spaßige Teil meiner Arbeit.
Wie es funktioniert
Mein Ziel ist es, eine selbstaktualisierende (aktuelle) Datenbank auf meinem Server zu haben, die immer nur die Daten der letzten paar Tage/Wochen enthält, so dass die Indizes nicht zu groß werden und Schreiboperationen daher immer mit maximaler Leistung ausgeführt werden. Wenn ein Client eine Anfrage stellt, um die neuen Erwähnungen, Follower usw. für einen Account zu erhalten, sucht der Server in dieser (aktuellen) Datenbank und gibt die Zeilen sofort zurück.
Nachdem ich einige Stunden darüber nachgedacht hatte, kam ich zu dem Schluss, dass mein Server in einem definierten Intervall automatisch neue Datenbanken erstellen und die alte Datenbank regelmäßig in ein Backup-Verzeichnis verschieben muss. Da ich mit SQLite arbeite, kann dies viel einfacher und schneller erfolgen als mit MySQL. Das Skript zum Parsen neuer Blöcke und zum Bearbeiten/Erstellen der Backup-DBs wird von einem Cronjob auf dem Server ausgeführt. Der Dateiname für jede Datenbank im Sicherungspfad enthält Informationen über den Datumsbereich der darin gespeicherten Daten, sodass der Server nicht durch Millionen von Zeilen wandern muss, um Daten für einen bestimmten Tag abzurufen. Dadurch kann ich auch ältere Kontovorgänge sehr schnell anzeigen.
Ich habe viel Erfahrung in der professionellen Datenbankadministration/-entwicklung und habe viele Jahre mit verschiedenen großen Anbietern wie Oracle, Informix, Sybase (ASA) und MySQL gearbeitet. Nichtsdestotrotz habe ich mich für eine rein dateibasierte Art von Datenbank entschieden und SQLite scheint hier die perfekte Wahl für mich zu sein (MongoDB würde auch funktionieren und wäre wahrscheinlich meine zweite Wahl). Dies ermöglicht es mir unter anderem, externe DB-Dateien (z.B. aus dem Sicherungsverzeichnis) einfach an eine bestehende Verbindung zur Haupt- (aktuellen) DB anzuhängen und die Daten innerhalb einer SELECT-Anweisung (oder auch mehrerer UNIONs) zu verbinden.
Bessere Komprimierung
Da ich so viel Speicherplatz wie möglich sparen möchte, habe ich einen eigenen Komprimierungsalgorithmus für die Operationen geschrieben. Einige von euch wissen vielleicht, dass die Transaktionen aus vielen redundanten Daten bestehen, die viel besser gespeichert werden können, als einfach nur den kompletten JSON-String in eine Spalte zu schreiben. Soweit ich weiß, hat @dan kürzlich ähnliche Optimierungen für EOS vorgenommen. Bevor die Daten deflationiert werden, werden die Eigenschaftsnamen im JSON-Objekt durch 'Eigenschafts-IDs' ersetzt, die automatisch in Form einer 'JSON-IDs-Tabelle' gespeichert werden.
In der Theorie ist es getan
Eine Sache, die ich auf meiner Reise als Entwickler gelernt habe, ist die Wichtigkeit, Zeit in die Planung und das Nachdenken über verschiedene Szenarien zu investieren, die in einer Produktionsumgebung auftreten können. Ich weiß, dass SteemWorld eine große Anzahl von Anfragen erhalten wird und darauf möchte ich gut vorbereitet sein. In den meisten Fällen führen später gemachte, große Änderungen in einem laufenden System zu mehr Kopfschmerzen und manchmal unvorhersehbaren Folgen.
Wenn man also momentan keine Änderungen in der SteemWorld sieht, liegt das daran, dass die Hauptarbeit im Hintergrund auf vielen Zetteln Papier stattfindet ;) Da ich momentan fast täglich neue Ideen für die Seite erhalte, denke ich darüber nach, einen zusätzlichen Post für Ideen/Feedback/Bug-Tracking zu erstellen und einen Link dort hin auf SteemWorld.org zu platzieren, damit andere sich austauschen und sehen können, was bereits geplant ist.
Bitte habt etwas Geduld und bedenkt, dass dies alles nur von mir alleine entwickelt wird. Ich weiß, dass im Tool noch viele schöne Funktionen fehlen und ich werde weiter daran arbeiten, sobald die Web-API stabil läuft. Wie bereits erwähnt, wird mein aktueller Schritt es mir ermöglichen, viele coole Dinge wie Desktop-Benachrichtigungen für Erwähnungen / Follower, eine performante Übersicht für eingehende Delegationen und SP-Ränge zu realisieren, wie es auf steemwhales.com früher mal der Fall war.
In the meantime...
New buttons for showing the incoming/outgoing votes:
https://steemitimages.com/DQmXA9RBqr2qRTbWpcnvGDv38v9v6gak6WotkLMMUZxeERk/hr_thin.png
Links
SteemWorld.org/@YourAccountName
- Introduction
- English
-
Newsletters
- Newsletter #1 / January, 2018
-
Related Posts
- Some thoughts on the CSI...
https://steemitimages.com/DQmXA9RBqr2qRTbWpcnvGDv38v9v6gak6WotkLMMUZxeERk/hr_thin.png
The Web API will make many awesome things possible on SteemWorld. As soon as I reach the point where I'm able to pay my bills with my work for the community, I will make it publicly accessible on a fast @privex server so that every developer can use it to easily retrieve data from the blockchain and to build/improve their own Steem tools.