<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: debricked</title>
    <description>The latest articles on DEV Community by debricked (@debrickedab).</description>
    <link>https://dev.to/debrickedab</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F313595%2Fb9db1b1e-a02d-470c-99fc-347ccf84539c.png</url>
      <title>DEV Community: debricked</title>
      <link>https://dev.to/debrickedab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/debrickedab"/>
    <language>en</language>
    <item>
      <title>
Cloning All Github Data – How, Why and Everything in Between</title>
      <dc:creator>debricked</dc:creator>
      <pubDate>Fri, 07 May 2021 11:26:11 +0000</pubDate>
      <link>https://dev.to/debrickedab/cloning-all-github-data-how-why-and-everything-in-between-3am0</link>
      <guid>https://dev.to/debrickedab/cloning-all-github-data-how-why-and-everything-in-between-3am0</guid>
      <description>&lt;p&gt;&lt;em&gt;&lt;a href="https://debricked.com"&gt;Debricked&lt;/a&gt; has achieved a not so small feat – we are now able to actively keep and maintain a clone of all data on GitHub! For what reason? You may ask. To understand all the why’s and how’s we have interviewed our Head of Data Science, Emil Wåréus.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Before we start with the questions, who are we talking to?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;My name is Emil and I’m the Head of Data Science at Debricked. Me and my team of 5 data engineers are the masters behind everything related to data. Also, I was the second employee at Debricked! &lt;/p&gt;

&lt;h2&gt;
  
  
  Debricked Cloning Github Data – Why?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Let’s start with the million dollar question: why would anyone want a copy of all GitHub data?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The short answer is – to have a better and faster representation of the data that we need to service our customers. You see, we want to do big computations on all open source. Yes! You heard that right. On &lt;em&gt;all&lt;/em&gt; open source.&lt;/p&gt;

&lt;p&gt;If we only wanted to monitor a couple of thousands of open source projects we could do it through the API calls provided by default.&lt;/p&gt;

&lt;p&gt;But our products and solutions are not meant to give customers partial coverage; it’s supposed to be extensive. Therefore we decided to index all 28M projects on GitHub, and that’s not the end of it. Soon we will be adding the other large repositories such as Gitlab, and more.&lt;/p&gt;

&lt;p&gt;But doing this, cloning all of GitHub that is, poses quite an interesting challenge because of the many different data structures and relational dependencies in the data. Some can be loosely coupled and some can be tight.&lt;/p&gt;

&lt;p&gt;As a result, huge challenges arise regarding the time complexity for calculations on such a large dataset. For these reasons we decided to go on a journey and see if we could create an up to date hourly mirror of GitHub locally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do you choose to store the data locally?&lt;/strong&gt;&lt;br&gt;
Haha! Yes, that may sound a bit unintuitive in the era of free cloud credits. But the truth is that it saves us a lot of money. Because the RAM and CPU load is high at all times, constantly chugging data, it is more cost-efficient.&lt;/p&gt;

&lt;p&gt;Cloud is great when you have variable loads such as ML training. But when you are pushing a model like ours, scraping data with a lot of database interactions, it is a lot cheaper to host it on prem. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For all the hardware geeks out there, what does a setup like this look like?&lt;/strong&gt;&lt;br&gt;
There are a couple of things at play. First, we have a relational database that is not too large, meaning not in the terabyte space. Second, in terms of cloning all the repositories we are looking at about 20 terabytes of data. Third, we have a graph database in which we want to understand how the open source relates to one another.&lt;/p&gt;

&lt;p&gt;For this we use Neo4j. Essentially we are doing graph computations to answer questions such as “what are the root dependencies” and “what open source impacts what open source”. &lt;/p&gt;

&lt;p&gt;The final component of the puzzle is to do the actual scraping and analytics. Here we have a cluster with a couple of hundred pods working in parallel to both gather and analyse the incoming data. &lt;/p&gt;

&lt;p&gt;What people don’t realise is that there is a lot of complexity to this. Just cloning a repository is not enough. We need the history of it and we need to create multiple snapshots of the data for different points in time. This multiplies the problem by many factors.&lt;/p&gt;

&lt;p&gt;And before I forget, all of that storage is of course on PCI-Express NVMe SSDs sending Gigabytes of data for analysis every second. We must also thank AMD for creating such nice server CPUs with many cores! 🙂 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TWgbD4mT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpqdrf3gxr8cmqodfszr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TWgbD4mT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpqdrf3gxr8cmqodfszr.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Emil, smiling when thinking about his beautiful server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;20 terabytes sounds like a lot of data – what does it entail exactly?&lt;/strong&gt;&lt;br&gt;
There are about 10 000 – 30 000 new pull requests each hour at GitHub. This is 5-10 times more than about 5 years ago, and that’s only the open source contributions on GitHub! We are monitoring about +40M repositories, 100M issues, 80M pull requests and 12M active users.&lt;/p&gt;

&lt;p&gt;Thanks to our technology, both hardware and software, we are able to keep our model up to date within the hour. So, whenever someone makes a pull request, comments, stars something or follows someone new we can collect that data with minimal time lag.&lt;/p&gt;

&lt;h3&gt;
  
  
  A new way of Identifying Vulnerabilities
&lt;/h3&gt;

&lt;p&gt;How did you go about setting this up? Did you wake up one day and think “I need to clone Github”? What triggered it?&lt;br&gt;
Haha, no. Of course not! We did GitHub scraping early on in the history of Debricked. It all started when we realised that a lot of vulnerabilities are discussed in issues and we wanted to link and classify those. Through research we realised that this data turned out to be highly relevant.&lt;/p&gt;

&lt;p&gt;About 2% of all issues are related to security, but only 0.2% are correctly labeled with a security tag. It is not until much later in time that those discussions are publicly disclosed as vulnerabilities through NVD and other sources of curated vulnerability information. &lt;/p&gt;

&lt;p&gt;To curb this, we developed our own machine learning models to classify issues as security related or not. This way we can provide customers with a huge security demand information about issues that may be a risk, but which have not turned into officially disclosed vulnerabilities yet. &lt;/p&gt;

&lt;p&gt;I must brag and say that we have achieved state of the art in the security text/issue classification space and have surpassed previous research in the area. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How many Vulnerabilities have you discovered this way so far?&lt;/strong&gt;&lt;br&gt;
About 200 000. In contrast the probably most popular database for vulnerability information NVD (Natural Vulnerability Database) has about 130 000 where a lot of them are not directly related to open source. We are also investigating how we could properly disclose this data to the public. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How did this later on translate to gathering all of the Github data?&lt;/strong&gt;&lt;br&gt;
We realised that this data (issues and vulnerabilities) is not independent from pull requests etc, which could provide us with additional signal to our models. For this reason we started to scrape commits, releases, code diffs etc., and perform lots of interesting calculations on the data. &lt;/p&gt;

&lt;p&gt;We discovered that with stronger links between vulnerabilities and the original source (the open source projects) we could increase the precision of our data dramatically. This turned out to be a quite technical machine learning solution.&lt;/p&gt;

&lt;p&gt;We match the software bill of materials to vulnerabilities and leverage all of our different data points which give us superior data quantity and quality in terms of accurately finding vulnerabilities in our customers proprietary code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Open Source Security – more than just Vulnerabilities
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;But the data is not only used for security, right?&lt;/strong&gt;&lt;br&gt;
Correct! As our customers will know, we are also providing health data on open source projects. For example, we look at the trend of super users commits to a certain repository to build scores which will give us intel about the project’s well being.&lt;/p&gt;

&lt;p&gt;This is a good example of how complex the data can be. You want to monitor the contributors who know their way around a project and see that they keep contributing. This, in combination with all the other data we have on a project, can give us an indication of its health.&lt;/p&gt;

&lt;p&gt;So, in essence data has become our core here. Gathering, understanding and enriching data from GitHub and other sources has enabled Debricked to create services unheard of before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This all sounds great! But what does this mean for current Debricked customers and potential future users?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most impactful part of it is that you get more accurate information on vulnerabilities. We correctly map vulnerabilities to repositories at GitHub, commits, issues etc. which in turn increases our confidence that a vulnerability actually affects an open source project, and gives us insight into how it is affected.&lt;/p&gt;

&lt;p&gt;This is a problem in general in our industry; the precision of the vulnerabilities that you are presented with in your Software Composition Analysis tools, Vulnerability Scanners etc.&lt;/p&gt;

&lt;p&gt;It is a difficult challenge to match the description of vulnerabilities and vulnerability information in for example email threads and other highly unstructured data sources to the actual software they affect. And then to find out if you are using that open source component and determine how you are using it and if you are in fact affected by the vulnerability. &lt;/p&gt;

&lt;p&gt;Good tools have 85-95% precision (True Positive rate). While we have seen competitors and free tools go as low as 60%, Debricked currently has a 90-98% precision rate on the languages we fully support. We manage this while being one tenth of the size of some of our competitors. This would not be possible without the data combined with our algorithms and raw talent in the team. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A little bird whispered that this might open doors for some interesting new functionalities?&lt;/strong&gt;&lt;br&gt;
Yes! I can’t tell you all the secrets just yet… But by having all this data we are able to determine if a vulnerability affects a certain class or function. A vulnerability is only relevant if you are using the class or function containing the vulnerability in your software.&lt;/p&gt;

&lt;p&gt;This can remove second order false positives and increase the accuracy of your internal triaging of the vulnerability. You will know exactly where in your code the vulnerability is, and if the code is called. This greatly reduces the amount of vulnerabilities you actually have to check, which will save a lot of time. So, stay tuned!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thanks a lot for your time Emil! Is there anything else you would add?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes. Keep an eye on our blog for some cool insights later on, both about this and other fun stuff! 🙂&lt;/p&gt;

</description>
      <category>devops</category>
      <category>github</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Debugging Docker performance issues on Dell XPS 15 7590</title>
      <dc:creator>debricked</dc:creator>
      <pubDate>Fri, 21 Feb 2020 13:00:54 +0000</pubDate>
      <link>https://dev.to/debrickedab/debugging-docker-performance-issues-on-dell-xps-15-7590-5bbm</link>
      <guid>https://dev.to/debrickedab/debugging-docker-performance-issues-on-dell-xps-15-7590-5bbm</guid>
      <description>&lt;p&gt;We recently bought a new set of laptops to Debricked, and since I’m a huge fan of Arch Linux, I decided to use it as my main operating system. The laptop in question, a Dell XPS 15 7590, is equipped with both an Intel CPU with built-in graphics, as well as a dedicated Nvidia GPU. You may wonder why this is important to mention, but at the end of this article, you’ll know. For now, let’s discuss the performance issues I quickly discovered.&lt;/p&gt;

&lt;h1&gt;
  
  
  Docker performance issues
&lt;/h1&gt;

&lt;p&gt;Our development environment makes heavy use of Docker containers, with local folders bind mounted into the containers. While my new installation seemed snappy enough during regular browsing, I immediately noticed something was wrong when I had setup my development environment. One of the first steps is to recreate our test database. This usually takes around 3-4 minutes, but I can admit I was eagerly looking forward to benchmark how fast this would be on my new shiny laptop.&lt;/p&gt;

&lt;p&gt;After a minute I started to realize that something was terribly wrong.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;16 minutes and 46 seconds later&lt;/strong&gt;, the script had finished, and I was disappointed. Recreating the database was almost five times as slow as on my old laptop! Running the script again using &lt;code&gt;time ./recreate_database.sh&lt;/code&gt;, I got the following output:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;real 16m45.615s&lt;br&gt;
user  2m16.547s&lt;br&gt;
sys  13m3.622s&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What stands out is the extreme amount of time spent in kernel space. What is happening here? A quick check on my old laptop, for reference, showed that it only spent 4 seconds in kernel space for the same script. Clearly something was way off with the configuration of my new installation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Debug all the things
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Disk I/O
&lt;/h2&gt;

&lt;p&gt;My initial thought was that the underlying issue was with my partitioning and disk setup. All that time in the kernel must be spent on something, and I/O wait seemed like the most likely candidate. I started by checking the Docker storage driver, since I’ve heard that the wrong driver can severely affect the performance, but no, the storage driver was &lt;code&gt;overlay2&lt;/code&gt;, just as it was supposed to be.&lt;/p&gt;

&lt;p&gt;The partition layout of the laptop was a fairly ordinary LUKS+LVM+XFS layout, to get a flexible partition scheme with full-disk encryption. I didn’t see a particular reason why this wouldn’t work, but I tested several different options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using ext4 instead of XFS,&lt;/li&gt;
&lt;li&gt;Create an unencrypted partition outside LVM,&lt;/li&gt;
&lt;li&gt;Use a ramdisk&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After using a ramdisk, and still getting an execution time of 16 minutes, I realised that clearly disk I/O can’t be the culprit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s really going on in the kernel?
&lt;/h2&gt;

&lt;p&gt;After some searching, I found out about the very neat perf top tool, which allows profiling of threads, including threads in the kernel itself. Very useful for what I’m trying to do!&lt;/p&gt;

&lt;p&gt;Firing up &lt;code&gt;perf top&lt;/code&gt; at the same time as running the &lt;code&gt;recreate_database.sh&lt;/code&gt; script yielded the following very interesting results, as can be seen in the screenshot below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cp2dTI82--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://debricked.com/blog/wp-content/uploads/2020/02/dockerlinus-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cp2dTI82--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://debricked.com/blog/wp-content/uploads/2020/02/dockerlinus-1.png" alt="Debugging Docker Performance Issues on Dell XPS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s a lot of time spent in &lt;code&gt;read_hpet&lt;/code&gt; which is the High Precision Event Timer. A quick check on my other computers showed that no other computer had the same behaviour. Finally I had some clue on how to proceed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;While reading up on the HPET was interesting on its own, it didn’t really give me an immediate answer to what was happening. However, in my aimless, almost desperate, searching I did stumble upon a couple of threads discussing the performance impact of having HPET either enabled or disabled when gaming.&lt;/p&gt;

&lt;p&gt;While not exactly related to my problem - I simply want my Docker containers to work, not do any high performance gaming - I did start to wonder which of the graphics cards that was actually being used on my system. After installing Arch, the graphical interface worked from the beginning without any configuration, so I hadn’t actually selected which driver to use: the one for the integrated GPU, or the one for the dedicated Nvidia card.&lt;/p&gt;

&lt;p&gt;After running &lt;code&gt;lsmod&lt;/code&gt; to list the currently loaded kernel modules, I discovered that modules for both cards were in fact loaded, in this case both &lt;code&gt;i915&lt;/code&gt; and &lt;code&gt;nouveau&lt;/code&gt;. Now, I have no real use for the dedicated graphics card, so having it enabled would probably just draw extra power. So, I blacklisted the modules related to &lt;code&gt;nouveau&lt;/code&gt; by adding them to &lt;code&gt;/etc/modprobe.d/blacklist.conf&lt;/code&gt;, in this case the following modules:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;blacklist nouveau&lt;br&gt;
blacklist rivafb&lt;br&gt;
blacklist nvidiafb&lt;br&gt;
blacklist rivatv&lt;br&gt;
blacklist nv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Upon rebooting the computer, I confirmed that only the &lt;code&gt;i915&lt;/code&gt; module was loaded. To my great surprise, I also noticed that &lt;code&gt;perf top&lt;/code&gt; no longer showed any significant time spent in &lt;code&gt;read_hpet&lt;/code&gt;. I immediately tried recreating the database again, and finally I got the performance boost I wanted from my new laptop, as can be seen below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;real 2m36.722s&lt;br&gt;
user 1m39.528s&lt;br&gt;
sys  0m2.674s&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As you can see, almost no time is spent in kernel space, and the total time is now faster than the 3-4 minutes of my old laptop. Finally, to confirm, I whitelisted the modules again, and after a reboot the problem was back! Clearly the loading of &lt;code&gt;nouveau&lt;/code&gt; causes a lot of overhead, for some reason still unknown to me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So there you go, apparently having the wrong graphics drivers loaded can make your Docker containers unbearably slow. Hopefully this post can help someone else in the same position as me to get their development environment up and running at full speed.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>performance</category>
      <category>nvidia</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
