<?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 Yogender Purohit on Medium]]></title>
        <description><![CDATA[Stories by Yogender Purohit on Medium]]></description>
        <link>https://medium.com/@yogenderpurohit20?source=rss-fb88dbd1da6c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yGJcsRg83gjqw23q1J9QwQ.jpeg</url>
            <title>Stories by Yogender Purohit on Medium</title>
            <link>https://medium.com/@yogenderpurohit20?source=rss-fb88dbd1da6c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:58:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yogenderpurohit20/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[How to setup python flask application on production & Scale it for high TPS]]></title>
            <link>https://medium.com/@yogenderpurohit20/how-to-setup-python-flask-application-on-production-scale-it-for-high-tps-a708d6c67803?source=rss-fb88dbd1da6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a708d6c67803</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[uwsgi]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Yogender Purohit]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 07:27:24 GMT</pubDate>
            <atom:updated>2020-06-24T07:32:22.786Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to setup python flask application on production &amp; scale it for high TPS</h3><p><strong>Basic introduction to NGINX, uWSGI &amp; Flask:</strong></p><p><strong>NGINX:</strong><br> It is an open source HTTP Web server and reverse proxy server. It is also used for caching, load balancing, media streaming, etc.</p><p><strong>uWSGI:<br></strong>It is a Web Server Gateway Interface (WSGI) server implementation that is typically used to run Python web applications.</p><p><strong>Flask:<br></strong>It is a web framework for Python, meaning that it provides functionality for building web applications, including managing HTTP requests and rendering templates.</p><h4><strong>Production Environment Prerequisites:</strong></h4><p>Follow below steps to fulfil the prerequisites of flask application in production environment:</p><ol><li>Install NGINX ( <a href="https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/">https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/</a>)</li><li>Install python ( <a href="https://realpython.com/installing-python/%22%20%5Cl%20%22linux">https://realpython.com/installing-python/#linux</a>)</li><li>Install following python packages using pip:<br> — uWSGI<br> — Flask</li></ol><h4><strong>Setup &amp; run flask application:</strong></h4><p>Follow below steps to run your flask application in production environment:</p><ul><li>First of all, create a file to define uWSGI configuration as per your project. For this, create new “<strong>.ini</strong>” file &amp; put the below almost ready configuration in it:</li></ul><blockquote>[uwsgi]<br>base=&lt;ABS_PATH_TO_YOUR_API_CODEBASE&gt;<br>chdir=%(base)<br>module = app<br>socket = &lt;SOCKET_FILE_PATH&gt;<br>chmod-socket = &lt;SOCKET_FILE_PERMISSIONS&gt;<br>vacuum = true<br>master = true<br>processes = &lt;TOTAL_NUMBER_OF_UWSGI_THREADS&gt;<br>die-on-term = true<br>ignore-sigpipe = true<br>ignore-write-errors = true<br>disable-write-exception = true<br>logger=file:&lt;LOG_FILE_PATH&gt;</blockquote><ul><li>Create a uWSGI service file under ‘/etc/systemd/system/’ directory with ‘&lt;UWSGI_SERVICE_NAME&gt;.service’ as name to run uWSGI daemon as a service under <strong>systemd</strong>. In this service file use below mentioned configuration:</li></ul><blockquote>[Unit]<br>Description=Your uWSGI Emperor<br>After=syslog.target<br>[Service]<br>ExecStart=&lt;UWSGI_BIN_PATH&gt; — ini &lt;YOUR_uwsgi.ini_PATH&gt;<br>RuntimeDirectory=uwsgi<br>Restart=always<br>KillSignal=SIGQUIT<br>Type=notify<br>StandardError=syslog<br>NotifyAccess=all<br>[Socket]<br>ListenStream=&lt;SOCKET_FILE_PATH_SAME_AS_uwsgi.ini&gt;<br>[Install]<br>WantedBy=multi-user.target</blockquote><ul><li>Next we need to configure a virtual host in NGINX configuration. Below is an example configuration(/etc/nginx/conf.d/default.conf):</li></ul><blockquote>server {<br> listen 80;<br>server_name localhost;<br>location /api/v1 {<br>include uwsgi_params;<br>rewrite ^/api/v1/(.*) $1 break;<br>uwsgi_pass unix:&lt;YOUR_SOCKET_FILE_PATH&gt;;<br>}<br>}</blockquote><ul><li>Now start your UWSGI service&amp; restart NGINX by following command:</li></ul><blockquote>service &lt;YOUR_SERVICE_FILE_NAME&gt; start;<br> systemctl restart nginx;</blockquote><p><strong>Congratulations!! your flask application is up &amp; running.</strong></p><h4><strong>Key points regarding configuration changes for serving high TPS application:</strong></h4><ul><li>For API’s which are serving high TPS (roughly more than 100 TPS from single node), Please make following configurational changes in your <strong>uwsgi.ini</strong> file to scale your API for handling high TPS:</li></ul><blockquote>processes=&lt;For normal application it should be 3–4 &amp; for high volume API’s it should be higher (Ex. 100)&gt;<br>listen=&lt;Max number of requests application can handle in parallel. By default, it is 100.&gt;</blockquote><ul><li>If you want to set ‘<strong>listen</strong>’ property value to more than 100 then first check what’s the configured unix max connection values by following command:</li></ul><blockquote>cat /proc/sys/net/core/somaxconn</blockquote><ul><li>If it is equals or greater than the value which you set in ‘<strong>listen’</strong> property then fine else update it by following command:</li></ul><blockquote>sysctl -w net.core.somaxconn=&lt;NEW_MAX_CONN_VAL&gt;</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a708d6c67803" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable authentication in apache spark web UI?]]></title>
            <link>https://medium.com/@yogenderpurohit20/how-to-enable-authentication-in-apache-spark-web-ui-d0b26149651a?source=rss-fb88dbd1da6c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0b26149651a</guid>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[spark-ui]]></category>
            <category><![CDATA[spark-streaming]]></category>
            <dc:creator><![CDATA[Yogender Purohit]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 06:35:20 GMT</pubDate>
            <atom:updated>2020-06-24T06:37:26.381Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache Spark is considered to be one of the top unified analytics engine for large-scale data processing. Beginning with spark is quite easy, almost everything is well integrated except few like Spark web UI authentication.</p><p>Spark does not provide any built-in authentication mechanism for its web UI. So, you need a javax servlet filter to implement the authentication in Spark web UI.</p><p>Spark also supports access control to the web UI when an authentication filter is present. Each application can be configured with its separate access control lists (ACLs). Spark differentiates between “view” permissions (who is allowed to see the application’s UI), and “modify” permissions (who can do things like kill jobs in a running application).</p><p>To implement spark web authentication in your application, please follow below steps:</p><ol><li>First of all, it needs <a href="https://docs.oracle.com/javaee/6/api/javax/servlet/Filter.html">javax servlet filters</a> to enable web UI authentication. Follow below link to get the basic authentication java code to build a JAR file. <br><a href="https://www.fortytools.com/blog/servlet-filter-for-http-basic-auth">https://www.fortytools.com/blog/servlet-filter-for-http-basic-auth</a><br>Or, download it from<strong> </strong><a href="https://www.dropbox.com/s/cb57pyufxqaawb5/BasicAuthFilter-0.0.1.jar?dl=0"><strong>here</strong></a>.</li><li>Move JAR file to spark jars directory (i.e. “<strong>$SPARK_HOME/jars/</strong>”).</li><li>Now go to “<strong>$SPARK_HOME/conf/</strong>” directory &amp; open “<strong>spark-defaults.conf</strong>” file. If this file is not present, then make a copy of “<strong>spark-defaults.conf.template</strong>” file &amp; name it as “<strong>spark-defaults.conf</strong>”.</li><li>Put this configuration in “spark-defaults.conf” as mentioned below:<br><em>spark.ui.filters </em><strong><em>&lt;FILTER_CLASS_NAME&gt;</em></strong><em><br> spark.com.fortytools.servlet.BasicAuthFilter.param.user </em><strong><em>&lt;USER_VAL&gt; </em></strong><em><br> spark.com.fortytools.servlet.BasicAuthFilter.param.password </em><strong><em>&lt;PASSWORD_VAL&gt;</em></strong><em><br> spark.com.fortytools.servlet.BasicAuthFilter.param.realm </em><strong><em>&lt;REALM_VAL&gt;</em></strong></li><li>If you’re using Spark cluster, then you need to follow step 1 to 4 for all cluster nodes.</li><li>Now restart the Spark cluster.</li><li>From now when someone opens a Spark web UI, a login popup will prompt &amp; after successful login you will be redirected to the Spark web UI.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*ByUEYDXtG6y5DQ3jP9EhHQ.png" /><figcaption>Login pop-up prompted when you open spark web UI</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0b26149651a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>