<?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 hadican on Medium]]></title>
        <description><![CDATA[Stories by hadican on Medium]]></description>
        <link>https://medium.com/@hadican?source=rss-8702befb21e1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CAEiSqRWv7N6RWLvwN70jQ.jpeg</url>
            <title>Stories by hadican on Medium</title>
            <link>https://medium.com/@hadican?source=rss-8702befb21e1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:35:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hadican/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[Hot-Warm-Cold Architecture with Elasticsearch]]></title>
            <link>https://medium.com/@hadican/hot-warm-cold-architecture-with-elasticsearch-8aa6e6db31c1?source=rss-8702befb21e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aa6e6db31c1</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[hadican]]></dc:creator>
            <pubDate>Wed, 25 Oct 2023 09:48:38 GMT</pubDate>
            <atom:updated>2023-10-25T09:48:38.725Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IFRi5h71pN5IaN7PyBL-xA.jpeg" /></figure><p>As new customers are joining our <strong><em>Journey to Zero </em></strong>at <strong>Intenseye</strong>, we do our best to give a better experience. To do so, we’ve updated our <strong>Elasticsearch</strong> architecture.</p><blockquote><strong><em>Elasticsearch</em></strong><em> is a distributed </em><strong><em>search</em></strong><em> and </em><strong><em>analytics</em></strong><em> engine built on </em><strong><em>Apache Lucene</em></strong><em>.</em></blockquote><p>Elasticsearch is mostly used for <strong>search</strong>, but we take advantage of the <strong>analytical power</strong> while calculating “<strong>compliance score</strong>” and producing “<strong>pathway analysis</strong>”. You can visit <a href="https://www.intenseye.com/"><strong>intenseye.com</strong></a> to learn much about these features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pRc1nA8QlZu039YAZd_rw.jpeg" /></figure><p>We work with existing <strong>cameras</strong> within <strong>facilities</strong> located around the <strong>world</strong>. We process <strong>streams</strong> frame by frame and notify <strong>unsafe</strong> acts. So the data we have is <strong>time-series</strong> data.</p><blockquote><strong><em>Time-series</em></strong><em> data is the data that has a </em><strong><em>timestamp</em></strong><em>, describing the moment in time when the data is produced.</em></blockquote><p>It can be a <strong>log</strong>, <strong>metric,</strong> or any <strong>time based-event</strong>. In time-series data, old documents become inherently insignificant.</p><p>Our <strong>customers</strong> were often interested in <strong>recent data</strong> (e.g. last 7 days) within a maximum time period. (e.g. 3 months) Based on this, we <strong>redesigned</strong> the <strong>architecture</strong> and changed a couple of things.</p><h3>1-) Data Streams</h3><p>First, we started using <strong>data streams</strong> instead of normal <strong>indices</strong>.</p><blockquote><strong><em>Data stream</em></strong><em> is kind of a </em><strong><em>wrapper</em></strong><em> of the classical Elasticsearch </em><strong><em>indices</em></strong><em>, and lets you store </em><strong><em>append-only</em></strong><em> time series data across </em><strong><em>multiple indices</em></strong><em> while giving you a </em><strong><em>single named resource</em></strong><em> for requests.</em></blockquote><p>You can submit <strong>indexing</strong> and <strong>search</strong> requests directly to a data stream. The stream <strong>automatically</strong> routes the request to <strong>backing indices</strong> that store the stream’s data.</p><p>The most <strong>recently</strong> created <strong>backing</strong> index is the data stream’s <strong>write</strong> index. The stream adds <strong>new documents</strong> to this index <strong>only</strong>. Every document indexed to a data stream must contain a <strong>@timestamp</strong> field, mapped as a <strong>date</strong> or <strong>date_nanos</strong> field type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0nmizdAbaQTUHCkaJABV7A.png" /></figure><p>When you submit a <strong>read</strong> <strong>request</strong> to a data stream, the stream <strong>routes</strong> the request to <strong>all</strong> its backing indices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7qMh4A8yWmf4UaqjlC3h5A.png" /></figure><p><strong>Data streams</strong> are well-suited for <strong>continuously</strong> generated data. So, instead of using <strong>normal</strong> indices, we switched to <strong>specialized</strong> indices, the data stream.</p><h3>2-) Index Lifecycle Management (ILM)</h3><p>To <strong>automate</strong> the management of these <strong>backing indices</strong> produced by data streams, we configured the <strong>Index Lifecycle Management</strong> (ILM).</p><blockquote><strong><em>ILM</em></strong><em> automatically manages </em><strong><em>indices</em></strong><em> according to your </em><strong><em>performance</em></strong><em>, </em><strong><em>resiliency</em></strong><em>, and </em><strong><em>retention</em></strong><em> requirements.</em></blockquote><p>With the help of ILM, you can do the following things:</p><ul><li><strong>Create</strong> a <strong>new index</strong> when an index reaches a certain <strong>size</strong> or <strong>number</strong> of <strong>documents</strong>, or for each <strong>day</strong>, <strong>week,</strong> or <strong>month.</strong></li><li><strong>Move </strong>documents between <strong>data tiers</strong>.</li><li><strong>Delete</strong> stale indices to enforce <strong>data retention</strong> standards.</li></ul><h3>3-) Data Tier</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*Tjv2lmiq9eo40aXVNJCGBQ.jpeg" /></figure><blockquote><em>A </em><strong>data tier</strong><em> is a collection of </em><strong><em>nodes</em></strong><em> with the same </em><strong><em>data role</em></strong><em>.</em></blockquote><ul><li><strong>Hot</strong> tier nodes handle the <strong>indexing</strong> <strong>load</strong> and hold your most <strong>recent</strong>, most-<strong>frequently-accessed</strong> data. Having an <strong>SSD</strong> and <strong>high a CPU</strong> is recommended.</li><li><strong>Warm</strong> tier nodes hold data accessed <strong>less-frequently</strong> and rarely need to be updated. <strong>Less</strong> <strong>performant</strong> hardware could be used here.</li><li><strong>Cold</strong> tier nodes hold data accessed <strong>infrequently</strong> and not normally updated. Having a cheap configuration could be used here.</li><li><strong>Frozen</strong> tier nodes hold data accessed <strong>rarely</strong> and <strong>never</strong> updated, kept in searchable snapshots.</li></ul><p>We <strong>combined</strong> what we’ve learned, and spin-up <strong>3</strong> <strong>hot</strong> nodes with <strong>high CPU</strong> + <strong>SSD</strong> and <strong>2 warm</strong> nodes with <strong>less performant CPU </strong>but larger <strong>HDD</strong>, and on top, created a <strong>data stream</strong> with <strong>ILM policy.</strong></p><pre><br>{<br>  &quot;policy&quot;: {<br>    &quot;_meta&quot;: {<br>      &quot;description&quot;: &quot;Compliance Score ILP&quot;<br>    },<br>    &quot;phases&quot;: {<br>      &quot;hot&quot;: {<br>        &quot;min_age&quot;: &quot;0ms&quot;,<br>        &quot;actions&quot;: {<br>          &quot;rollover&quot;: {<br>            &quot;max_age&quot;: &quot;2d&quot;<br>          }<br>        }<br>      },<br>      &quot;warm&quot;: {<br>        &quot;min_age&quot;: &quot;30d&quot;,<br>        &quot;actions&quot;: {<br>          &quot;shrink&quot;: {<br>            &quot;number_of_shards&quot;: 2<br>          },<br>          &quot;forcemerge&quot;: {<br>            &quot;max_num_segments&quot;: 1<br>          },<br>          &quot;readonly&quot;: {}<br>        }<br>      },<br>      &quot;delete&quot;: {<br>        &quot;min_age&quot;: &quot;90d&quot;,<br>        &quot;actions&quot;: {<br>          &quot;delete&quot;: {}<br>        }<br>      }<br>    }<br>  }<br>}</pre><ul><li>First, the added data is written in <strong>hot nodes</strong>.</li><li>After <strong>2 days</strong>, ILM <strong>rolls-over</strong> a new index and applies it for each consecutive 2 days.</li><li>After <strong>30 days</strong>, moves data from <strong>hot nodes</strong> to <strong>warm nodes</strong>, and <strong>shrinks/merges</strong> into <strong>2</strong> shards.</li><li>After <strong>90 days</strong>, deletes data from <strong>warm</strong> <strong>nodes</strong>.</li></ul><h3>Conclusion</h3><p>In terms of <strong>optimization</strong>, there are <strong>no</strong> limits in <strong>Elasticsearch</strong>. Yet thanks to <strong>data streams</strong>, <strong>data tiers,</strong> and <strong>ILM policies</strong>, we restrained the <strong>size</strong> and <strong>time</strong> of the indices, <strong>optimized</strong> the storage, and achieved <strong>high</strong> index &amp; query <strong>performance.</strong></p><h3>References</h3><ul><li><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html</a></li><li><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/data-tiers.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/data-tiers.html</a></li><li><a href="https://opster.com/guides/elasticsearch/capacity-planning/elasticsearch-hot-warm-cold-frozen-architecture/">https://opster.com/guides/elasticsearch/capacity-planning/elasticsearch-hot-warm-cold-frozen-architecture/</a></li><li><a href="https://medium.com/bestcloudforme/data-aging-with-elasticsearch-hot-warm-cold-infrastructure-6e5eef4c9e65">https://medium.com/bestcloudforme/data-aging-with-elasticsearch-hot-warm-cold-infrastructure-6e5eef4c9e65</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aa6e6db31c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Mesh with Linkerd2 | pt. 2]]></title>
            <link>https://medium.com/@hadican/service-mesh-with-linkerd2-pt-2-22741994929d?source=rss-8702befb21e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/22741994929d</guid>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[service-mesh]]></category>
            <category><![CDATA[linkerd2]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[hadican]]></dc:creator>
            <pubDate>Thu, 11 May 2023 09:51:01 GMT</pubDate>
            <atom:updated>2023-05-11T09:52:46.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ng-jVCyP60VE9Ap1QJ2_dA.png" /></figure><p>In the <a href="https://medium.com/@hadican/service-mesh-w-linkerd2-pt-1-39a6add12060"><strong>first part</strong></a> of our <strong>service mesh</strong> journey, we talked about “What is <strong>Service Mesh</strong> and why we chose <strong>Linkerd2</strong>?”. In this <strong>second part</strong>, we will be talking about <strong>the problems</strong> we faced and how we <strong>solved</strong> them.</p><h3>Problem #1: Apache ZooKeeper Leader Election</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*ak9SxlC6ukuhv3-3FLNMwQ.png" /></figure><blockquote><em>Apache Pulsar is a cloud-native, multi-tenant, high-performance distributed messaging and streaming platform originally created at Yahoo!</em></blockquote><p>Apache Pulsar uses <a href="https://zookeeper.apache.org/"><strong>Apache Zookeeper</strong></a> for metadata storage, cluster configuration, and coordination. After we meshed Zookeeper with Linkerd2, <strong>K8s</strong> restarted the pods one-by-one but they stuck in “<strong>CrashloopBackOff</strong>”.</p><p>We’ve checked the <strong>logs</strong> and saw that ZooKeeper cannot communicate with other cluster members. We dig more and found out Zookeeper nodes are <strong>unable</strong> to <strong>elect</strong> a <strong>leader</strong> due to mesh. ZooKeeper servers listen on three ports: <strong>2181</strong> for client connections, <strong>2888</strong> for follower connections — if they are the leader and <strong>3888</strong> for other server connections during the leader election phase.</p><p>Then, we checked the documentation and found the “<strong>skip-inbound-ports</strong>” and “<strong>skip-outbound-ports</strong>” parameters of the Linkerd2 sidecar. Once we add <strong>2888</strong> and <strong>3888</strong> ports to skip for inbound/outbound, then establishing quorum did work. Since these ports are for <strong>internal</strong> Zookeeper pod communication, it was OK to skip mesh.</p><p>This is a <strong>common</strong> problem for all <strong>service meshes</strong> if you use an application with leader election, such as; Pulsar, Kafka, etc. and this is the workaround.</p><h3>Problem #2: Fail-Fast Logs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*gVjxBguE2GbC_z3waQW-3Q.png" /></figure><p>We’ve started meshing our applications one by one. Everything was fine, until meshing one of the <strong>AI</strong> services, let’s call it <strong>application-a</strong>. We have another application running as 500+ <strong>lightweight</strong> pods, let’s call it <strong>application-b, </strong>which are<strong> </strong>making requests with <strong>gRPC</strong> to <strong>application-a</strong>.</p><p>After 1 or 2 mins of successful mesh, we were seeing hundreds of Failed to proxy request: HTTP Logical service in fail-fast errors in <strong>application-b</strong>. We&#39;ve checked the source code of linkerd-proxy the repository, and we&#39;ve found the place where this log was printed but couldn&#39;t understand the error message. I mean, what is HTTP Logical service?</p><p>So we’ve opened an <a href="https://github.com/linkerd/linkerd2/issues/5599"><strong>issue</strong></a> to Linkerd2 via <strong>GitHub</strong>. They took a <strong>close interest</strong> in the issue and tried to help us to solve it, even released a special package to <strong>debug</strong> the issue.</p><p>After all discussions, it turns out the value of <strong>“max_concurrent_streams” </strong>set on<strong> application-a,</strong> which was <strong>10</strong>, was not enough to handle requests.<strong> </strong>Linkerd2 made it visible. We’ve increased the value from <strong>10</strong> to <strong>100</strong>. No more <strong>fail-fast</strong> errors.</p><p>Special thanks to @olix0r and @hawkw from the Linkerd2 team.</p><h3>Problem #3: Outbound Connection Before Sidecar Initialization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*P1qxd1hp7p8UPPudIsu9VA.png" /></figure><p>We have a few applications making <strong>HTTP</strong> calls during application <strong>start-up</strong>. It needs to fetch some information <strong>before</strong> serving requests. So the application was trying to make an <strong>outbound connection</strong> before the Linkerd2 sidecar initialization, hence it was <strong>failing</strong>. <strong>K8S</strong> was restarting the <strong>application</strong> <strong>container </strong>(not the sidecar container) and during that time the sidecar was <strong>ready</strong>. So it was running fine after <strong>1</strong> application container <strong>restart</strong>.</p><p>Again, this is another <strong>common problem</strong> for all service meshes. There is no <strong>elegant</strong> solution for this. The very simple solution is putting “<strong>sleep</strong>” during startup. There is an open <a href="https://github.com/linkerd/linkerd2/issues/2704"><strong>issue</strong></a> on GitHub and a <a href="https://github.com/linkerd/linkerd-await"><strong>solution</strong></a> offered by Linkerd2 guys, which I believe requires much more work than putting “sleep”.</p><p>We left it <strong>as is</strong>. 1 automatic application container restart was solving the problem already.</p><h3>Problem #4: Prometheus</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*M3XFhjn0pfl4JaJ5W4BZfw.png" /></figure><blockquote><em>Prometheus is an open-source cloud-native application used for monitoring and alerting. It records real-time metrics in a time series database with flexible queries and real-time alerting.</em></blockquote><p>Linkerd2 stores its <strong>metrics</strong> in a Prometheus instance that runs as an extension. Even though Linkerd2 comes with its <strong>own</strong> Prometheus instance, we were using Prometheus already in our platform, and we just needed to <strong>re-use</strong> it.</p><p>Linkerd2 had a beautifully documented <a href="https://linkerd.io/2.10/tasks/exporting-metrics/"><strong>tutorial</strong></a> that allows you to bring your own Prometheus instance. We followed it and everything was working fine until we mesh an application that uses <strong>“</strong><a href="https://prometheus.io/docs/practices/pushing/"><strong>PushGateway</strong></a><strong>” </strong>from Prometheus to push our own internal metrics asides from the ones produced by Linkerd2.</p><blockquote><em>PushGateway is an intermediary service which allows you to push metrics from jobs which cannot be scraped/pulled.</em></blockquote><p>After mesh, the 500+ lightweight pods started to <strong>push</strong> metrics over the sidecar proxy. We started having <strong>memory issues</strong> on the PushGateway side and we skipped the mesh for <strong>9091</strong> (PushGateway port) from 500+ pods.</p><h3>Conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*sN4Cj83G-qqhHqvgW8Z4zw.jpeg" /></figure><p>Not everything is easy-peasy as <strong>Arya</strong> killed the <strong>Night King</strong>. Making changes in a <strong>running</strong> system has always been difficult. We knew we would be facing some <strong>obstacles</strong> while integrating with Linkerd2, yet we solved our problems one by one.</p><p>Now we’re living happily ever after.</p><h3>References:</h3><ul><li><a href="https://linkerd.io/">https://linkerd.io/</a></li><li><a href="https://prometheus.io/">https://prometheus.io/</a></li><li><a href="https://pulsar.apache.org/">https://pulsar.apache.org/</a></li><li><a href="https://youtu.be/3wGMV60wBm4">https://youtu.be/3wGMV60wBm4</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22741994929d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cost-Effective Scalability with Latency-Based Autoscaling]]></title>
            <link>https://medium.com/@hadican/cost-effective-scalability-with-latency-based-autoscaling-4345b799719b?source=rss-8702befb21e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4345b799719b</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[linkerd2]]></category>
            <dc:creator><![CDATA[hadican]]></dc:creator>
            <pubDate>Thu, 11 May 2023 08:34:59 GMT</pubDate>
            <atom:updated>2023-05-11T08:34:59.213Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j2DFOtC47t2TJeoRkBRdJA.jpeg" /></figure><p>One of the biggest <strong>challenges</strong> in modern <strong>cloud-native</strong> applications is to achieve <strong>high scalability</strong> while keeping <strong>costs low.</strong> Traditional auto-scaling approaches based on <strong>CPU</strong> or <strong>memory</strong> usage can be suboptimal, as they do not consider the <strong>latency</strong> of requests. In this blog post, we will explore how to implement a <strong>latency-based autoscaling</strong> strategy using <strong>Linkerd2</strong> and <strong>Prometheus</strong> using <strong>custom metrics</strong> on <strong>Kubernetes</strong>.</p><p><strong>Linkerd2</strong> is a <strong>service mesh</strong> for <strong>Kubernetes</strong>, that provides <strong>observability</strong>, <strong>security</strong>, and <strong>reliability</strong> features to microservices architectures. <strong>Prometheus</strong> is a popular <strong>monitoring</strong> and <strong>alerting</strong> system that can collect <strong>metrics</strong> from various sources, including Linkerd2. You can read about our Linkerd2 journey from <a href="https://medium.com/@hadican/service-mesh-w-linkerd2-pt-1-39a6add12060"><strong>here</strong></a> and <a href="https://www.intenseye.com/resources/service-mesh-with-linkerd2-part-2"><strong>here</strong></a>.</p><p>By combining these two tools, it is possible to implement a <strong>latency-based autoscaling</strong> strategy on <strong>Kubernetes</strong>, where the idea behind this is to set a <strong>target threshold</strong> for the <strong>response time</strong> of requests and then <strong>adjust</strong> the <strong>number of instances</strong> of an application to keep the response time <strong>below</strong> that <strong>threshold</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uddKmZ8cbkGkmlWQZyiPSQ.png" /><figcaption>Image from <a href="http://learnk8s.io/">learnk8s.io</a></figcaption></figure><p>To enable this type of autoscaling, first, we need to understand a couple of things like “<strong>Custom &amp; External Metrics</strong>”, “<strong>Prometheus Adapter</strong>” and “<strong>Horizontal Pod Autoscaler (HPA)</strong>”, assuming you’re using <strong>Linkerd2</strong> and <strong>Prometheus</strong> already.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFucNyuU-PFTlD874wQreA.png" /><figcaption>Image from <a href="http://learnk8s.io/">learnk8s.io</a></figcaption></figure><p><strong>Custom &amp; external metrics</strong> are important features in Kubernetes for <strong>monitoring</strong> and <strong>scaling</strong> applications. Custom metrics are <strong>application-specific</strong> metrics (e.g. number of requests per second, the average response time, or the number of errors) defined using the <strong>Custom Metrics API</strong> (<a href="http://custom.metrics.k8s.io/">custom.metrics.k8s.io</a>), while <strong>external metrics</strong> are collected from <strong>external systems</strong> (e.g. Apache Pulsar, Buildkite, etc.) using the <strong>External Metrics API</strong> (<a href="http://external.metrics.k8s.io/">external.metrics.k8s.io</a>).</p><p>Once you have defined these <strong>custom or external metrics</strong>, you can use a “<strong>Prometheus Adapter</strong>” to expose them to <strong>Kubernetes</strong>. The Prometheus Adapter acts as a <strong>bridge</strong> between <strong>Kubernetes</strong> and <strong>Prometheus</strong>, allowing you to use custom or external metrics to <strong>drive</strong> <strong>autoscaling</strong>.</p><p>Finally, you can use the <strong>Horizontal Pod Autoscaler (HPA)</strong> to <strong>automatically</strong> <strong>scale</strong> the number of <strong>pods</strong> in your deployment based on the custom or external metrics <strong>exposed</strong> by the <strong>Prometheus Adapter</strong>. The HPA <strong>continuously</strong> monitors the metrics and <strong>adjusts</strong> the number of <strong>pods</strong> up or down as needed to maintain the <strong>desired level of performance</strong>.</p><p><strong>Linkerd2</strong> exposes a bunch of <strong>metrics</strong>, which you can find all <a href="https://linkerd.io/2.12/reference/proxy-metrics/"><strong>here</strong></a>. You can use “<strong>response_latency_ms_bucket</strong>” to define a <strong>custom metric</strong> rule. There are various ways to configure <strong>Prometheus Adapter</strong> to <strong>expose</strong> custom metrics depending on how you installed the <strong>Prometheus</strong>. Here is how if you’ve installed via “<a href="https://github.com/prometheus-operator/kube-prometheus"><strong>kube-prometheus</strong></a>”:</p><pre>prometheusAdapter+: {<br>  namespace: &#39;monitoring&#39;,<br>  config+:: {<br>    rules: [<br>      {<br>        seriesQuery: &#39;response_latency_ms_bucket{namespace=&quot;deep-learning&quot;, pod!=&quot;&quot;}&#39;,<br>        seriesFilters: [],<br>        resources: {<br>          template: &#39;&lt;&lt;.Resource&gt;&gt;&#39;,<br>        },<br>        name: { matches: &#39;^(.*)_bucket$&#39;, as: &#39;${1}_90th&#39; },<br>        metricsQuery: &#39;histogram_quantile(0.90, sum(rate(&lt;&lt;.Series&gt;&gt;{&lt;&lt;.LabelMatchers&gt;&gt;, direction=&quot;inbound&quot;}[5m])) by (le, &lt;&lt;.GroupBy&gt;&gt;))&#39;<br>      }<br>    ],<br>  },<br>}</pre><p>The <strong>rule</strong> in the above snippet uses the “<strong>response_latency_ms_bucket</strong>” metric to <strong>calculate</strong> and <strong>expose</strong> a new metric, and also <strong>renames</strong> it to “<strong>response_latency_ms_90th</strong>”. You can find an awesome <strong>Prometheus Adapter</strong> configuration walkthrough <a href="https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/config-walkthrough.md"><strong>here</strong></a><strong>,</strong> that explains every line of the above configuration one by one, and the keywords like “<strong>&lt;&lt;.Resource&gt;&gt;</strong>”, “<strong>seriesQuery</strong>”, etc.</p><p>After adding a <strong>custom</strong> rule and <strong>restarting</strong> the Prometheus Adapter, you should be able to see it via:</p><pre>kubectl get --raw /apis/custom.metrics.k8s.io/v1beta2</pre><p>The <strong>response</strong> should be like this:</p><pre>{<br>  &quot;kind&quot;: &quot;APIResourceList&quot;,<br>  &quot;apiVersion&quot;: &quot;v1&quot;,<br>  &quot;groupVersion&quot;: &quot;custom.metrics.k8s.io/v1beta2&quot;,<br>  &quot;resources&quot;: [<br>    {<br>      &quot;name&quot;: &quot;jobs.batch/response_latency_ms_90th&quot;,<br>      &quot;singularName&quot;: &quot;&quot;,<br>      &quot;namespaced&quot;: true,<br>      &quot;kind&quot;: &quot;MetricValueList&quot;,<br>      &quot;verbs&quot;: [<br>        &quot;get&quot;<br>      ]<br>    },<br>    {<br>      &quot;name&quot;: &quot;namespaces/response_latency_ms_90th&quot;,<br>      &quot;singularName&quot;: &quot;&quot;,<br>      &quot;namespaced&quot;: false,<br>      &quot;kind&quot;: &quot;MetricValueList&quot;,<br>      &quot;verbs&quot;: [<br>        &quot;get&quot;<br>      ]<br>    },<br>    {<br>      &quot;name&quot;: &quot;pods/response_latency_ms_90th&quot;,<br>      &quot;singularName&quot;: &quot;&quot;,<br>      &quot;namespaced&quot;: true,<br>      &quot;kind&quot;: &quot;MetricValueList&quot;,<br>      &quot;verbs&quot;: [<br>        &quot;get&quot;<br>      ]<br>    },<br>    {<br>      &quot;name&quot;: &quot;deployments.apps/response_latency_ms_90th&quot;,<br>      &quot;singularName&quot;: &quot;&quot;,<br>      &quot;namespaced&quot;: true,<br>      &quot;kind&quot;: &quot;MetricValueList&quot;,<br>      &quot;verbs&quot;: [<br>        &quot;get&quot;<br>      ]<br>    }<br>  ]<br>}</pre><p>Now you can use exported “<strong>response_latency_ms_90th</strong>” metric to <strong>automatically</strong> <strong>scale</strong> the number of <strong>pods.</strong></p><pre>apiVersion: autoscaling/v2<br>kind: HorizontalPodAutoscaler<br>metadata:<br>  name: inference-server<br>  namespace: deep-learning<br>spec:<br>  minReplicas: 2<br>  maxReplicas: 10<br>  behavior:<br>    scaleUp:<br>      stabilizationWindowSeconds: 120<br>      policies:<br>        - type: Pods<br>          value: 1<br>          periodSeconds: 120<br>    scaleDown:<br>      stabilizationWindowSeconds: 180<br>      policies:<br>        - type: Pods<br>          value: 1<br>          periodSeconds: 180<br>  metrics:<br>    - pods:<br>        metric:<br>          name: response_latency_ms_90th<br>          selector: { }<br>        target:<br>          averageValue: &quot;100000m&quot;<br>          type: AverageValue<br>      type: Pods<br>  scaleTargetRef:<br>    apiVersion: apps/v1<br>    kind: Deployment<br>    name: inference-server</pre><p>In the above resource, the <strong>HPA</strong> has two types of scaling behaviors: <strong>scale-up</strong> and <strong>scale-down</strong>, with corresponding <strong>stabilization</strong> windows of <strong>2 minutes</strong> and <strong>3 minutes</strong>, respectively. The scale-up policy will <strong>add</strong> one replica every <strong>120 seconds</strong> if the response latency metric is <strong>above 100ms</strong> for the <strong>90th percentile</strong> of the pods. The scale-down policy will <strong>remove</strong> one replica every <strong>180 seconds</strong> if the response latency metric is below or equal to <strong>100ms</strong> for the same percentile.</p><p>You can find an <strong>awesome</strong> HPA configuration walkthrough <a href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-autoscaling/853-configurable-hpa-scale-velocity/README.md"><strong>here</strong></a><strong>,</strong> that <strong>explains</strong> every line of the above configuration one by one, and the keywords like “<strong>stabilizationWindowSeconds</strong>”, “<strong>periodSeconds</strong>”, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BN3xNViWS_zkQks1traAg.png" /><figcaption>x-axis: time, y-axis: latency (ms)</figcaption></figure><p>After combining all, as you can see in the <strong>screenshot</strong> when the latency is <strong>increased</strong>, autoscaler <strong>created</strong> new pods and <strong>adjusted</strong> <strong>latency</strong> to around <strong>100ms</strong> within the range of <strong>+-10%</strong>, which is a <strong>default</strong> tolerance value in K8s, <strong>globally</strong> <strong>configurable</strong> via a <strong>parameter</strong>. Check out <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details"><strong>here</strong></a> for the algorithm details.</p><p>If you run the below <strong>command</strong>:</p><pre>kubectl describe horizontalpodautoscalers -n deep-learning inference-server</pre><p>You’ll probably see something like this, with ups and downs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdoQH238tEgGsjlcI0WJUA.png" /></figure><p>In conclusion, <strong>latency-based autoscaling</strong> via <strong>Linkerd2</strong> and <strong>Prometheus</strong> can be a powerful tool for achieving <strong>cost-effective scalability</strong> and improving the <strong>performance</strong> of modern cloud-native applications. By <strong>dynamically</strong> <strong>adjusting</strong> the number of instances based on <strong>actual traffic demand</strong>, organizations can optimize their resource usage and provide <strong>better</strong> user experiences.</p><h3>Resources</h3><ul><li><a href="https://learnk8s.io/autoscaling-apps-kubernetes">https://learnk8s.io/autoscaling-apps-kubernetes</a></li><li><a href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-autoscaling/853-configurable-hpa-scale-velocity/README.md">https://github.com/kubernetes/enhancements/blob/master/keps/sig-autoscaling/853-configurable-hpa-scale-velocity/README.md</a></li><li><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/">https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/</a></li><li><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details">https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4345b799719b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Service Mesh with Linkerd2 | pt. 1]]></title>
            <link>https://medium.com/@hadican/service-mesh-w-linkerd2-pt-1-39a6add12060?source=rss-8702befb21e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/39a6add12060</guid>
            <category><![CDATA[service-mesh]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[linkerd]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[hadican]]></dc:creator>
            <pubDate>Fri, 24 Mar 2023 11:01:56 GMT</pubDate>
            <atom:updated>2023-05-11T09:52:04.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rO8MYUWTc4hOeo5c_V98-Q.png" /></figure><p>At <strong>Intenseye</strong>, we follow <strong>trends</strong> &amp; <strong>hype</strong> technologies and apply best practices while using them. We run thousands of pods on <strong>Kubernetes</strong> written with <strong>Scala</strong>, <strong>Kotlin</strong>, <strong>Go</strong>, <strong>Python,</strong> etc. and most of them use <strong>gRPC</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*3zYuHgvuXZKr6OEpcv8NXA.png" /></figure><p><strong>gRPC</strong> is a modern open-source high-performance remote procedure call (RPC) framework that uses <strong>HTTP/2</strong> for transport. HTTP/2 supports making multiple requests over a <strong>single TCP connection</strong> to reduce the number of round trips. This is where the problem emerges; <strong>load balance</strong>.</p><p>Once the connection is established, all requests will get pinned to a single destination pod. Thus, we won’t have a balanced load. We need an <strong>L7-aware</strong> load balancer, instead of an <strong>L4</strong>. You can read the details of the problem from <a href="https://linkerd.io/2018/11/14/grpc-load-balancing-on-kubernetes-without-tears/"><strong>here</strong></a> later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*NvrejJRgKencoVm6GTba3w.png" /></figure><p>We were seeking a solution for one other problem; <strong>secure</strong> transport between microservices. We have tens of components running hundreds of pods in total. Configuring <strong>TLS</strong> between all of them one by one was intimidating and would have been time-consuming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*ol4YYBI-o3M4Ul5MPkG_vg.png" /></figure><p>We also needed a <strong>monitoring</strong> system and <strong>traffic metrics</strong> from all of these components and microservices. We would like to observe <strong>success/failure</strong> rates, <strong>RPS</strong> of pods, who talks with who at which frequency, etc.</p><p>There was a single solution for these 3 problems we have: <strong>Service Mesh</strong></p><h3>What is a Service Mesh?</h3><blockquote><em>A service mesh is a tool for adding observability, security, and reliability features to applications by inserting these features at the platform layer rather than the application layer. (</em><a href="https://servicemesh.es/"><em>source</em></a><em>)</em></blockquote><p>The <strong>service mesh</strong> is typically implemented as a scalable set of network proxies deployed alongside application code; a pattern called a <strong>sidecar</strong>. These proxies handle the communication between the microservices and allow them to <strong>control traffic</strong> and <strong>gain insights</strong> throughout the system. Service Mesh offers great features, such as traffic metrics, circuit braking, mTLS, traffic split, retry &amp; timeout, A/B routing, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWocovCkqU0eJ5d26jIZug.png" /><figcaption><strong>source:</strong> servicemesh.es</figcaption></figure><p>We started digging into the details of service meshes and evaluated the features that are important to us, how can we benefit from them, etc. As service meshes impact the <strong>latency</strong> and <strong>resource</strong> consumption, these disadvantages have to be measured too. Since we had <strong>1000+</strong> pods, the resource cost would be <strong>1000 </strong>x<strong> sidecar</strong>. Plus, we were <strong>racing against time</strong> so the latency should have been minimal.</p><p>After some <strong>research</strong> and <strong>PoC</strong>, we decided to use <strong>Linkerd2</strong> between <strong>Istio</strong>, <strong>Consul</strong> and <strong>Linkerd2</strong>. I must say, <a href="https://servicemesh.es/"><strong>servicemesh.es</strong></a> helped us a lot to gain knowledge about service mesh and to compare the features between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*vVOCByZN0gpu_OJCfRUazA.png" /></figure><p>We chose <a href="https://github.com/linkerd/linkerd2"><strong>Linkerd2</strong></a> because of <strong>3 </strong>reasons compared to Istio and Consul, asides from the features we are seeking. (L7 LB, mTLS, traffic metrics, etc.):</p><ul><li><strong>Lightweight</strong> (low CPU &amp; memory consumption)</li><li><strong>Low latency</strong></li><li><strong>Latency aware LB</strong></li></ul><p><strong>Istio</strong> had plenty of nice features (thanks to <strong>Envoy</strong> proxy), but we did not need all of them. Also, its <strong>sidecar </strong>proxy <strong>CPU</strong> &amp; <strong>memory</strong> consumption was high compared to Linkerd2. <strong>Consul</strong> was using the same sidecar proxy, so we eliminated it as well. <a href="https://linkerd.io/2020/12/03/why-linkerd-doesnt-use-envoy/"><strong>Here</strong></a> is a detailed explanation of why Linkerd2 is using its proxy instead of Envoy. Plus, Linkerd2 was so <strong>easy to use</strong>. Istio&#39;s documentation was so overwhelming.</p><blockquote><em>Linkerd rhymes with “Cardi B”. The “d” is pronounced separately, as in “</em><strong><em>Linker-DEE</em></strong><em>”. (</em><a href="https://linkerd.io/2/faq/#how-do-i-pronounce-linkerd"><em>source</em></a><em>)</em></blockquote><h3>Solutions</h3><h4>Problem #1: gRPC Load Balance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOYXqqVdPKnHR8F4kezjdw.png" /><figcaption>without mesh / with mesh</figcaption></figure><p>As you can see in the graph, some pods were like scapegoats and some were like sloths. After the mesh, everything was fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*I9nXRvyHs6kymK9D2uIfag.gif" /></figure><h4>Problem #2: mTLS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*MPJInBbVbrx5ofCa2FO7xA.png" /></figure><p>Thanks to the <a href="https://linkerd.io/2/features/automatic-mtls/"><strong>mTLS</strong></a> feature of Linkerd2, we <strong>secured</strong> internal communication between microservices just like a finger snap as Thanos did. Linkerd2 automatically <strong>rotates</strong> certificates every 24 hours. Also, you can use <a href="https://linkerd.io/2/tasks/automatically-rotating-control-plane-tls-credentials/"><strong>cert-manager</strong></a> to rotate the issuer certificate and private key.</p><h4>Problem #3: Traffic Monitoring</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uosVet6c9EMRX_ChYoS0dg.png" /><figcaption><strong>source:</strong> linkerd.io</figcaption></figure><p>Linkerd2 is bundled with <a href="https://prometheus.io/"><strong>Prometheus</strong></a> and <a href="https://grafana.com/grafana/"><strong>Grafana</strong></a>, yet you can bring your instance and configure it via <a href="https://linkerd.io/2/tasks/external-prometheus/">official documentation</a>. We followed the documentation and started to use our existing instances. Now we have great metrics from each meshed pod and we have better observability over the cluster.</p><h3>Conclusion</h3><p>Thanks to Linkerd2, we solved our problems and now living happily ever after. The <a href="https://linkerd.io/2/reference/">documentation</a> was very clear, <a href="https://linkerd.io/2/getting-started/">getting started</a> page was so easy to follow (+ they had a demo application.) Of course, not everything was bright and shiny. We faced a few issues while meshing pods or after mesh but we solved them as well. Even we opened an <a href="https://github.com/linkerd/linkerd2/issues/5599">issue</a> on GitHub and got help.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*QKafAd5RK3dY4Tqg8zI0sg.jpeg" /></figure><p>So this post is the <strong>first part</strong> of our service mesh <strong>journey</strong> which is about “What is Service Mesh and why we chose Linkerd2?” In the <a href="https://medium.com/@hadican/service-mesh-with-linkerd2-pt-2-22741994929d"><strong>second</strong> <strong>part</strong></a>, we will be talking about the <strong>problems</strong> we faced and how we solved them.</p><h3>References:</h3><ul><li><a href="https://servicemesh.es/">https://servicemesh.es/</a></li><li><a href="https://linkerd.io/">https://linkerd.io/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39a6add12060" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Simple Artificial Neural Network (ANN)]]></title>
            <link>https://medium.com/@hadican/how-to-build-a-simple-artificial-neural-network-ann-a064939f940b?source=rss-8702befb21e1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a064939f940b</guid>
            <category><![CDATA[artificial-neural-network]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[hadican]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 10:28:39 GMT</pubDate>
            <atom:updated>2019-03-28T10:40:30.878Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hnr2hOHmoJpRayw55gjuwQ.png" /><figcaption>Google Trends Results, March 2014-2019</figcaption></figure><p>Asides from <strong>Kylie Jenner, TikTok </strong>videos and <strong>Tesla</strong>, people are searching for these <strong>new terms</strong> given in the graph and want to learn more about. Even, you may have come here yet you’ve searched any of these terms.</p><blockquote>“AI is the new electricity.” — <a href="https://www.andrewng.org/">Andrew Ng</a></blockquote><p><strong>Artificial Neural Networks</strong> (ANN) are inspired by the <strong>human brain</strong> and are built to simulate the interconnected processes that humans do: <strong>thinking.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*Jx97VUn1i4GFBbD6G11eyg.png" /><figcaption>Side-by-side <strong>illustrations</strong> of biological and artificial neurons.</figcaption></figure><p>Basically, an <strong>ANN</strong> consists of the following components:</p><ul><li>An input layer</li><li>A hidden layer w/<a href="https://medium.com/the-theory-of-everything/understanding-activation-functions-in-neural-networks-9491262884e0"><strong>Activation Function</strong></a></li><li>An output layer</li><li>Weights between the layers</li></ul><p>Best way to <strong>understand</strong> neural networks is to <strong>build one from scratch</strong>, <strong>without</strong> using any deep learning library. In this article, we will be exactly doing this, with <strong>Python.</strong></p><blockquote>“Talk is cheap. Show me the code.” — <a href="https://github.com/torvalds">Linus Torvalds</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*-FVmQuWQgGp85wEnH924CA.png" /></figure><p>So, we have above table. As we <strong>humans</strong>, we directly understand the output is always equal to the first column value of input section.</p><p>We will <strong>create</strong> and <strong>train</strong> an artificial neural network, and it will <strong>predict</strong> the output value for given <strong>new</strong> input value, as provided in the last row.</p><p>Let’s create our <strong>neural network</strong> class. Yes, we said we will not use any <strong>deep learning </strong>library, but we will use <strong>numpy</strong> for calculations. You can install with:</p><pre>pip install numpy</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7360f91fcb6a2f06fce6e986a3a9c365/href">https://medium.com/media/7360f91fcb6a2f06fce6e986a3a9c365/href</a></iframe><p>We have created the class and created randomly generated synaptic weights.</p><p>The <strong>activation function</strong> used in our model will be <strong>sigmoid</strong>. This function can map any value to a value from 0 to 1. We will use this function to normalize the weighted sum of the inputs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a233b1076899b899180a6c0b030260b6/href">https://medium.com/media/a233b1076899b899180a6c0b030260b6/href</a></iframe><p>The <strong>think()<em> </em></strong>function will take an array as input, and will return the dot product of input and the weight matrix.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98f581ad96dd0290aebb4893ba40e05f/href">https://medium.com/media/98f581ad96dd0290aebb4893ba40e05f/href</a></iframe><p>Now we are ready to <strong>train</strong> our artificial neural network to make an accurate prediction. Every input will have a <strong>weight</strong>, which may be either <strong>positive</strong> or <strong>negative</strong>, where we assigned <strong>randomly</strong> in the beginning. These weights needs to be <strong>changed</strong>, cannot be static values. Otherwise it will not be a “<strong>learning</strong>”. So, how we will change these values?</p><p>The answer is; <strong>Back-Propagation.</strong></p><p>We will <strong>predict</strong> from train set input, calculate the <strong>error </strong>since we know the result, do the <strong>adjustments</strong>, and do all these 3 steps over and over again (about 10.000 times) to fine tune weights.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/341f365b14d21d43265bb0714d0b686b/href">https://medium.com/media/341f365b14d21d43265bb0714d0b686b/href</a></iframe><p><strong>Now</strong> we are ready to sail towards the <strong>unknown</strong>!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c5b215c404a6ce34c01ae2a6ea190ac/href">https://medium.com/media/4c5b215c404a6ce34c01ae2a6ea190ac/href</a></iframe><p>This is the output when we ran the code:</p><pre>&gt; python main.py<br>Weights in the Beginning:<br>[[ 0.85619597]<br> [ 0.44821289]<br> [-0.89561481]<br> [ 0.39085635]]<br>Weights After Training:<br>[[ 8.96880175]<br> [-2.94541369]<br> [-2.30839168]<br> [-4.3796263 ]]<br>The answer for [1 0 1 0] is: 1</pre><pre>&gt; python main.py<br>Weights in the Beginning:<br>[[ 0.13915639]<br> [-0.50739333]<br> [ 0.13890921]<br> [ 0.80830971]]<br>Weights After Training:<br>[[ 8.94700038]<br> [-3.61970704]<br> [-1.65339981]<br> [-4.36980354]]<br>The answer for [0 0 1 0] is: 0</pre><p><a href="https://github.com/hadican/simple-artificial-neural-network"><strong>Here</strong></a> you can find the <strong>entire code</strong> for this simple artificial neural network.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a064939f940b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>