<?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 கார்த்திக் on Medium]]></title>
        <description><![CDATA[Stories by கார்த்திக் on Medium]]></description>
        <link>https://medium.com/@ehrktia?source=rss-3b5026584b62------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cqrThCvN_0r_DYcv.jpeg</url>
            <title>Stories by கார்த்திக் on Medium</title>
            <link>https://medium.com/@ehrktia?source=rss-3b5026584b62------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 06:01:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ehrktia/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[Golang pprof singleton performance]]></title>
            <link>https://ehrktia.medium.com/golang-pprof-singleton-performance-7fdd6e790c06?source=rss-3b5026584b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fdd6e790c06</guid>
            <category><![CDATA[pprof]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[singleton]]></category>
            <dc:creator><![CDATA[கார்த்திக்]]></dc:creator>
            <pubDate>Fri, 10 Dec 2021 19:42:31 GMT</pubDate>
            <atom:updated>2021-12-10T19:42:31.275Z</atom:updated>
            <content:encoded><![CDATA[<p>I always wanted to check and measure performance of simple things to learn about the concept in depth. Is impossible due to time constraint and work load mostly.Recently had some time on my own so thought why not do a refresher on golang pprof. Current golang applications are distributed microservices, whose performance and run times are measured using specialised tool which is not scope of this article. The article focus on using inbuilt pprof to measure the performance of a simple constructor function which creates a new instance of struct and validate the fields inside struct based on the <a href="https://pkg.go.dev/github.com/go-playground/validator/v10">validator</a> rules defined for fields. Below content is based on simple experiment to create an instance of struct using constructor and validate its fields using 3 different approaches.</p><ol><li>Create a new instance of validator for each call towards the constructor.</li><li>Pass in an instance of validator as one of the input parameter for constructor.</li><li>Use global singleton instance of validator across the app.</li></ol><p>With out further due here are the findings.</p><p>simple user struct used for the experiment</p><pre>type User struct {<br>Fname, Lname, Addr1, City, Postcode string`validate:&quot;required&quot;`<br>Addr2 string<br>}</pre><p>New constructor is being used to create a new instance of user instead of declaring it directly.</p><p>For simplicity sake the postcode is defined as string and having required rule i.e- for demo purposes we are expecting a string in postcode field if not present we raise validation error using validator. The same applies to name validation as well, expecting string of any length.</p><h4>Approach -1</h4><p>First approach being, to create new instance of validator inside constructor as shown below , so for each call to the constructor new instance of validator being initialised and used.</p><pre>func NewUser(fname, lname, addr1, city, pcode string) (*User, error) {<br> v := validator.New()<br> i := &amp;User{<br>  Fname:    fname,<br>  Lname:    lname,<br>  Addr1:    addr1,<br>  City:     city,<br>  PostCode: pcode,<br> }<br> if err := v.Struct(i); err != nil {<br>  return nil, err<br> }<br>}</pre><p>A simple bench mark function is used to capture time taken to intialise new user using constructor.</p><pre>func benchmarkNewUser(b *testing.B) {<br>    for i := 0; i &lt; b.N; i++ {<br>        _,_= NewUser(b.Name(), b.Name(), b.Name(),b.Name(),b.Name(),b.Name(), b.Name())</pre><pre>}<br>}<br>func BenchmarkNewUser(b *testing.B) {<br>    benchmarkNewUser(b)<br>}</pre><p>count : 5 is the number of times is benchmark ran.</p><pre>goos: linux<br>goarch: amd64<br>cpu: Intel(R) Core(TM) i7–10510U CPU @ 1.80GHz<br>BenchmarkNewUser-8 46929 22373 ns/op<br>BenchmarkNewUser-8 52742 21238 ns/op<br>BenchmarkNewUser-8 53509 21459 ns/op<br>BenchmarkNewUser-8 49224 22353 ns/op<br>BenchmarkNewUser-8 54099 22435 ns/op<br>PASS<br>ok 7.099s</pre><h4>Approach -2</h4><p>Second approach is, to pass in validator instance as one of the input parameter to constructor.</p><pre><br>func NewUser(parm1,parm2,parm3 string,v *validator.Validate) (*instance,error){<br>i:=&amp;instance{<br>parm1,parm2,param3<br>}<br>if err:=v.Struct(i);err!=nil{<br>return nil,err<br>}<br>}</pre><p>Both count number and the benchmark remains the same as first approach.</p><pre>goos: linux<br>goarch: amd64<br>cpu: Intel(R) Core(TM) i7–10510U CPU @ 1.80GHz<br>BenchmarkNewUser-8 46929 22373 ns/op<br>BenchmarkNewUser-8 52742 21238 ns/op<br>BenchmarkNewUser-8 53509 21459 ns/op<br>BenchmarkNewUser-8 49224 22353 ns/op<br>BenchmarkNewUser-8 54099 22435 ns/op<br>PASS<br>ok 7.099s</pre><p>Negligible amount of improvement in ops.</p><h4>Approach -3</h4><p>Final approach the wining one is to create a global instance of validator and use it in the package.</p><pre>import{<br>“github.com/ehrktia/bank/app/utils/validate”<br>}<br>//todo move this to main func <br>func init(){<br>validate.NewValidator()<br>}<br>func NewUser(parm1,parm2,parm3 string)(*instance,error){<br>i:=&amp;instance{<br>parm1,parm2,parm3<br>}<br>if err:=validate.Validate.Struct(i);err!=nil{<br>return nil,err<br>}<br>}</pre><p>here we initialise a validator in main function by calling the NewValidator()<br>which in turn creates new instance of validator ready to be used in application.</p><p>validate.go</p><pre>var Validate *Validate.Validator<br>var once &amp;sync.Once{}<br>func NewValidator(){<br>once.Do(func(){<br>Validate=validator.New()<br>}<br>)<br>}</pre><p>Inside validate pkg, a global variable Validate is declared and this is initialised by NewValidator() .To ensure we initialize only one instance of the validator globally it is called in under <a href="https://cs.opensource.google/go/go/+/go1.17.5:src/sync/once.go;l=14">sync</a> once do function.</p><pre><br>goos: linux<br>goarch: amd64<br>cpu: Intel(R) Core(TM) i7–10510U CPU @ 1.80GHz<br>BenchmarkNewUser-8 2005014 636.3 ns/op<br>BenchmarkNewUser-8 1879420 579.7 ns/op<br>BenchmarkNewUser-8 1891534 594.4 ns/op<br>BenchmarkNewUser-8 1735612 590.9 ns/op<br>BenchmarkNewUser-8 1888153 681.4 ns/op<br>PASS<br>ok 9.255s</pre><p>considerable improvement in op/s reduced from 23kns/op to 600ns/op.</p><h4>Conclusion :</h4><p>if any third party package used inside app offers concurrent safe instance better to create global instance and use it across app.</p><p>Foot Note: please correct me if am wrong , provide me with your valuable feedback which would help me grow in all aspects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fdd6e790c06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why should we meditate?]]></title>
            <link>https://ehrktia.medium.com/why-should-we-meditate-b22f90f23b92?source=rss-3b5026584b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22f90f23b92</guid>
            <dc:creator><![CDATA[கார்த்திக்]]></dc:creator>
            <pubDate>Sat, 15 May 2021 21:41:51 GMT</pubDate>
            <atom:updated>2021-05-15T21:41:51.193Z</atom:updated>
            <content:encoded><![CDATA[<p>I am sure almost all of the people who are reading this blog have a bank account. The answer to the question why we need a bank account is very obvious. A bank account is required to save money which can be used later in times of need. Bigger or smaller, depending on the circumstances, we withdraw, deposit and spend. The system of savings has existed since the beginning of mankind. In old days people in India used to store money in the form of coins &amp; jewellery in the floor of the house. Not just money but food used to be stored too. The need to save money or food comes from our basic survival instinct that in order to survive we need to have a backup at all times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xo1IAnrg6wQAjNSmGPkDYA.jpeg" /></figure><p>The same way we treat money to be used in crisis, what is it that we can use when we face problems in waking life? What do we have in store to deal with such situations? Spirituality is the wealth, that gives strength &amp; courage to deal with the adversities of life. A spiritually inclined person has a different way of dealing with challenging times. They understand the nature of life and are aware that everything is impermanent. Whenever a person spends time with self in reflection he/she is accumulating a wealth, an abundance that reflects in the attitude and behaviour of the person. It acts like a mountain which does not flicker no matter how strong the winds are.</p><p>Meditation makes you calm and relieves stress……is the biggest misconception in today’s world. Sometimes meditation itself can stress you out. Practicing Once a week makes you feel relaxed and energised but that’s not even the tiniest bit of what it actually is. Thanks to the western approach and various scientific studies, it is seen as a visit to the spa. Meanwhile, I have never understood why we need scientific validations to follow our beliefs and practices? Various books on meditation, specially the buddhist ones mention that this was one of the best kept secrets for thousands of years and only recently it was discovered by western masters and is now being used widely by many sections of the society. It was never hidden, just like the sun and the moon it was always there, but only a true seeker can find the treasure. In my opinion, mediation is a very strict discipline which requires dedication, hard work and right approach. A monk spends approximately 10 years in a monastery to master a discipline, hence, it must be something worth spending that much time. It takes a very sincere effort to train the mind. As with learning other things there will be failures, ups and downs, frustrations but one can overcome all hurdles. Every single moment spent in sadhana counts, like a pot of gold which keeps filling up like an asset.</p><p>In today’s world, we have gone miles away from ourselves. We need apps to tell us how much to eat? What to eat? How much to walk? How much to sleep? How to sleep? We have gone far away from our own body and mind. We do not know why we are suffering from this many issues in our lives. People are not in touch with themselves. That’s another reason for our outward approach because we are looking for solutions outside. Awareness of senses, breath, mind, feelings and body is all lost somewhere in the world of selfies and smartphones. Meditation is what connects us to ourselves. Its a path towards inside which develops an insight where we are no longer dependent on our senses for perception. Some people believe that mediation is just a sitting practice with some fancy candles and oil burners. (Yes, that’s how they show in movies!!). Some think its for old people who do not have much to do in life. In reality, it is much more than that. On this path, there is no fullstop and no the end, it just keeps going. Every day is a new realisation. It soaks the mind in a never ending bliss, a state of joy which no matter the condition, never leaves. It teaches us to fall in love endlessly with the marvel of every creation we see, every tiny fleck of nature….its magnanimous. One starts loving not just self but all beings and all creation and when they lose the discrimination between themselves and other entities(living and non living), they begin to RISE!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22f90f23b92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[so what are you]]></title>
            <link>https://ehrktia.medium.com/so-what-are-you-af62482e2122?source=rss-3b5026584b62------2</link>
            <guid isPermaLink="false">https://medium.com/p/af62482e2122</guid>
            <dc:creator><![CDATA[கார்த்திக்]]></dc:creator>
            <pubDate>Sat, 15 May 2021 21:38:17 GMT</pubDate>
            <atom:updated>2021-05-15T21:43:59.376Z</atom:updated>
            <content:encoded><![CDATA[<h3>so what are you holding on to</h3><p>When I was leaving college after completing graduation, I was aware I won’t be able to see my friends for a long time, maybe years. So we all planned for a final meet-up in a local mall/plaza. I wanted to watch a movie before I was leaving the city forever as my father had retired from serving in the army and we were finally going to settle down in our hometown. I asked all my friends from the group except one because every time we wanted to go watch a movie, she wouldn’t get permission from her home and this would make others guilt ridden, as a result they would back off one by one. so, this time I decided to exclude her as I didn’t want anyone to spoil the last get together. I was aware that morally this was wrong but I just went ahead with it. we all had a nice time but unfortunately she came to know about this through my other friend. I was feeling guilty but somewhere my mind justified that this was right because I knew she wouldn’t have come at any cost and that would have ruined the entire plan.</p><p>I left the city and got busy with life. I never got the chance to speak with her for many years. It became very difficult to stay in touch with all the friends. Facebook wasn’t very popular those days, Whatsapp was available only on smartphones with a hefty internet expense and calls weren’t cheap either. One day I was speaking with my friend who just happened to be with her. During the conversation he passed on the phone to her. I spoke to her after almost 6 years. After the pleasantries were exchanged and a little gossip, I said to her, ‘’I have a feeling you are still keeping that incident in your head. I could sense it all these years and now when I’m talking to you I can feel it in your voice.” she replied, ‘yes, you could have at least asked.’ I said, ‘yes, but anyways you wouldn’t have come.’ to which she answered that it was only fair if you asked me. I did finally apologise for my actions but I was surprised to find that all these years she was keeping this inside her. She never bothered to Call me because she was holding on to that against me.</p><p>In these many years I have seen many people keeping grudge against their friends, colleagues, relatives, even parents. I’m not a saint to say that I haven’t had any enmities for anyone ever. I had animosity against some people who did some horrible things to me and treated me poorly. Eventually I realised its not doing me any good. How does my holding anger against someone affects their health in any way? Except it only damages my sanity. When things went south with my ex-boss, I didn’t realise the gravity of the blow at that time. I was furious for many years. I had resentment and it took me a considerable amount of time to let go of that outrage. Only when I tried to move on I realised how much resentment I had bottled up inside me, letting go of it at last made me feel lighter and happier .</p><p>“how could he say that?” ” you know what he did?” “how could she do that to me?” “nobody asked me, I will never forget that”. all these statements represent repressed emotions. We are waiting to lash out at that person who made us feel miserable at that moment but all the while holding onto it like a ball of fire. Buddha said in his teachings, “Holding on to anger is like grasping a hot coal with the intent of throwing it at someone else; you are the one who gets burned.”</p><p>Having said that letting go is essential for self annihilation it is although very difficult to let go entirely from our minds. We never know how much bitterness we are carrying unless we try to get rid of it. But that doesn’t mean we shouldn’t attempt to liberate ourselves. Holding onto grudge brings out only the negative aspects of mind and makes it foggy. A fuzzy mind cannot clearly see what’s beyond the perception of the eye. To let go truly one must learn to forgive. Forgiving one for their actions is the biggest virtue. By letting go we rise over the basic human tendencies. If you have anger and animosity towards someone that made you bitter in your life, try to forgive them for their mistakes. Make a list of all the people and one by one, try to pardon them for their mistakes, their anger, harsh tone and wrongdoings. It can take months to absolve all those hidden emotions.</p><p>As much as forgiving is important its also crucial to ask for it if deep down you are aware of something you did to someone. It clears up heart and one is free from bondage. One must travel light. Life becomes heavy if we carry too much baggage. If we can’t carry anything with us then why carry grudge?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af62482e2122" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>