<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lukáš Prokein on Medium]]></title>
        <description><![CDATA[Stories by Lukáš Prokein on Medium]]></description>
        <link>https://medium.com/@LukasP?source=rss-7f432dc30b08------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ALy6h8M6n9oCrJA1.jpg</url>
            <title>Stories by Lukáš Prokein on Medium</title>
            <link>https://medium.com/@LukasP?source=rss-7f432dc30b08------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 08:42:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@LukasP/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using batch processing to speed up large jobs on Amazon Neptune]]></title>
            <link>https://medium.com/thinknum/using-batch-processing-to-speed-up-large-jobs-on-amazon-neptune-3c29bc028ac?source=rss-7f432dc30b08------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c29bc028ac</guid>
            <category><![CDATA[amazon-neptune]]></category>
            <category><![CDATA[gremlins]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <dc:creator><![CDATA[Lukáš Prokein]]></dc:creator>
            <pubDate>Fri, 13 Mar 2020 12:23:25 GMT</pubDate>
            <atom:updated>2020-03-13T12:23:25.685Z</atom:updated>
            <content:encoded><![CDATA[<p>One of our key data transformation features in <a href="https://kgbase.com/">KgBase</a> is <strong>Convert to relationship</strong>. It allows you to convert your raw flat data into relationships directly in KgBase. In this example I imported CSV file with 1000 rows of citations which I want to visualize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HsVqzTlBjSm6j63INbbUlg.png" /><figcaption>Raw citations data imported in KgBase</figcaption></figure><p>Each record has information such as title and authors. I would like to visualize papers, authors and connections between them. For that I applied <strong>Convert to relationship</strong> on <strong>Authors</strong> column which extracted authors from each paper into a separate table, and created link_many relationships.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fo6XnOKHQEJxWqe74LAqlA.png" /><figcaption>Citations project after converting to relationships</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vd4xr_L4HmJQxVrnH2eFfg.png" /><figcaption>Graph view of citations relationships</figcaption></figure><p>This blog post is about what’s going on under the hood. Our initial implementation for this feature was basic, but worked fine for smaller datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*O4afunY5s13GGGnYqdE7CA.png" /><figcaption>Initial implementation flowchart</figcaption></figure><p>As we started to work with more data, transformation became slower and even timed-out on several datasets. We needed to implement more reliable and faster solution. The main speed issue was caused by executing too many small Gremlin queries while processing data. To fix that, we decided to implement data processing in batches using bigger combined Gremlin queries.</p><h4><strong>The new algorithm works like this:</strong></h4><ol><li>Get chunk of nodes that have not been processed yet</li><li>Parse raw values to relationship items</li><li>Create new nodes by chunks</li><li>Create edges by chunks</li><li>Clear raw values</li><li>Get next chunk of nodes or finish</li></ol><h4>Processing in chunks</h4><p>Basic Gremlin query for creating a new node looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35464be5a548b4ea7b0ed9e5725dcfce/href">https://medium.com/media/35464be5a548b4ea7b0ed9e5725dcfce/href</a></iframe><p>We can batch this process by appending next node create query at the end of current query. Using loop we are creating one bigger Gremlin query that will create chunk of nodes (for example 50 nodes in one query). Different Gremlin implementations can have different limitations in terms of query size. For example Apache TinkerPop server which we use for local development gives you an error <strong>Max frame length of 65536 has been exceeded</strong> when you exceed the maximum query length. So you need to find an optimal chunk size.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c690d34132a0f9e7871189673843034f/href">https://medium.com/media/c690d34132a0f9e7871189673843034f/href</a></iframe><p>Likewise you can batch create edges:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c43e3db4b7b0719ce8ce518eca688253/href">https://medium.com/media/c43e3db4b7b0719ce8ce518eca688253/href</a></iframe><p>Clearing raw values can be batched as well. In Python you can unpack your list of node ids to arguments using *:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55660a0e0868e16c662f849b17e604e9/href">https://medium.com/media/55660a0e0868e16c662f849b17e604e9/href</a></iframe><h4><strong>Apache TinkerPop vs. Amazon Neptune</strong></h4><p>We use Apache TinkerPop as a local development server while working on KgBase. There are some differences in implementation between TinkerPop and our production graph database Amazon Neptune. Here are two things I found during batch processing implementation:</p><p>When updating property value you need to specify Cardinality.single to replace existing value otherwise new value will be just added but not replaced.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/053299adf11e2404f8e040d1b06caf06/href">https://medium.com/media/053299adf11e2404f8e040d1b06caf06/href</a></iframe><p>Second thing that I had to debug for a while was that with limit applied, Neptune would return nodes in different order as my local TinkerPop instance. I used this query to get a chunk of nodes that have not been processed yet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7173a86d74c6b0d607914b015456de6d/href">https://medium.com/media/7173a86d74c6b0d607914b015456de6d/href</a></iframe><p>Then I executed next steps of the relationship conversion algorithm — as described earlier — so extracting values, creating new nodes and edges. To perform the last step, which is clearing original raw values, I tried to reuse this existing query by cloning it and performing .property(Cardinality.single, &quot;authors&quot;, &quot;&quot;) directly on it as it worked fine on my local TinkerPop server. But Neptune database matched this query to different set of nodes — not the same ones as in initial query and so it cleared values on non-processed nodes. I was not able to find what caused this issue, but I already had a list of node ids in my algorithm so I used that in new Gremlin query to clear original values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a9bd07e5e34904d11915d1b607d677e/href">https://medium.com/media/1a9bd07e5e34904d11915d1b607d677e/href</a></iframe><p>This table shows comparison of processing time with a samples from CSV of 1000 and 5000 citations. I was converting authors to <strong>link_many</strong> relationships. Each citation has between 1–10 authors. This batch processing implementation rewrite brought us significant speed improvement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c29bc028ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thinknum/using-batch-processing-to-speed-up-large-jobs-on-amazon-neptune-3c29bc028ac">Using batch processing to speed up large jobs on Amazon Neptune</a> was originally published in <a href="https://medium.com/thinknum">Thinknum</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>