avatarRoxanna Azimy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4324

Abstract

span> <span class="hljs-params">(c *calculator)</span></span> Calculate(num... <span class="hljs-type">int</span>) { ans := <span class="hljs-number">0</span> <span class="hljs-keyword">for</span> _, n := <span class="hljs-keyword">range</span> num { ans += n } fmt.Println(ans) }

<span class="hljs-keyword">var</span> Calculator calculator</pre></div><p id="c1d0">We exposed a struct which implements the method Calculate. This is required for the discovery and registration of the plugin. Now to compile this and make it a shared-object we need to build the library as a plugin.</p><div id="b6b4"><pre><span class="hljs-attribute">go build -o -buildmode</span>=plugin .</pre></div><p id="198a">After this, we will have a shared object file(in our case “<i>add.so</i>”) which we can dynamically load at runtime in our main application.</p><figure id="5129"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*HEBnzWVkvUP0JjhOsfOH7Q.png"><figcaption>updated file structure of the library</figcaption></figure><p id="5408">Now to dynamically load the library into our main application at run time we need use the plugin system of Golang.</p><div id="0960"><pre><span class="hljs-keyword">import</span> ( <span class="hljs-string">"fmt"</span> <span class="hljs-string">"os"</span> <span class="hljs-string">"plugin"</span> )

<span class="hljs-keyword">type</span> Calculator <span class="hljs-keyword">interface</span> { Calculate(num... <span class="hljs-type">int</span>) }

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> { calculatorPlugin, err := plugin.Open(<span class="hljs-string">"/abs/path/to/shared/object/file"</span>) <span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> { fmt.Println(<span class="hljs-string">"error while opening shared object file"</span>) os.Exit(<span class="hljs-number">1</span>) }

symCalculator, err := calculatorPlugin.Lookup(<span class="hljs-string">"Calculator"</span>) <span class="hljs-keyword">if</span> err != <span class="hljs-literal">nil</span> { fmt.Println(<span class="hljs-string">"error while lookup"</span>) os.Exit(<span class="hljs-number">1</span>) }

<span class="hljs-keyword">var</span> calculator Calculator calculator, ok := symCalculator.(Calculator) <span class="hljs-keyword">if</span> !ok { fmt.Println(<span class="hljs-string">"unexpected type from module symbol"</span>) os.Exit(<span class="hljs-number">1</span>) }

calculator.Calculate(<span class="hljs-number">3</span>,<span class="hljs-number">4</span>) }</pre></div><p id="f4f9">In this case if we are making any changes to library, we don’t need to re-compile our main application. We only need to recompile the library’s shared object and rerun our main application.</p><p id="a32d">Due to the different characteristics, the advantages and disadvantages of static and dynamic libraries are also obvious; binaries that rely only on static libraries and are generated by static linking can be executed independently because they contain all the dependencies, but the compilation result is also larger. Dynamic libraries can be shared among multiple executables, which can reduce the memory footprint, and their linking process is often triggered during loading or running, so they can contain some modules that can be hot-plugged and reduce the memory footprint. Compiling binaries using static linking has very obvious deployment advantages, and the final compiled product will run directly on most machines. The deployment benefits of static linking are far more important than the lower memory footprint, that’s why Golang uses static linking as the default linking method.</p><h1 id="d290">Issues with Dynamic-linking (shared library plugins) in Go</h1><p id="91cd">Plugins using shared libraries and the plugin package work well for Golang, as the previous section demonstrates. However, this approach also has some serious downsides. The most important downside is that Golang is very picky about keeping the main application and the shared libraries it loads compatible.</p><p id="285c">As an experiment, try using different versions of a common d

Options

ependency in the plugin application and the main application, rebuild the main application and run it. Most likely you’ll get this error:</p><div id="443c"><pre><span class="hljs-comment">"plugin was built with a different version of package XXX"</span></pre></div><figure id="d928"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*ow5zqQqWHmQoZqaC.gif"><figcaption></figcaption></figure><p id="35aa">The reason for this is that Golang wants all the versions of all packages in the main application and plugins to match exactly. It’s clear what motivates this: safety.</p><p id="7b0e">Consider C and C++ as counter-examples. In these languages, an application can load a shared library with dlopen and subsequently use dlsym to obtain symbols from it. dlsym is extremely weakly typed; it takes a symbol name and returns a void*. It’s up to the user to cast this to a concrete function type. If the function type changes because of a version update, the result can very likely be some sort of segmentation fault or even memory corruption.</p><p id="80a8">Since Golang relies on shared libraries from plugins, it has the same inherent safety issues. It tries to protect programmers from shooting themselves in the foot by ensuring that the application has been built with the same versions of packages as all its plugins. This helps avoid mismatch. In addition, the version of the Golang compiler used to build the application and plugins must match exactly.</p><p id="74b9">However, this protection comes with downsides — making developing plugins somewhat cumbersome. Having to rebuild all plugins whenever any common packages change — even in ways that don’t affect the plugin interface — is a heavy burden. Especially, considering that by their very nature plugins are typically developed separately from the main application; they may live in separate repositories, have separate release cadences etc.</p><h1 id="bfc1">Alternative approaches to shared library plugins in Golang</h1><p id="c642">Given that the plugin package was only added to Go in <a href="https://golang.org/doc/go1.8">version 1.8</a> and the limitation described previously, it’s not surprising that the Go ecosystem saw the emergence of alternative plugin approaches.</p><p id="87e5">One of the innovative approaches involves plugins via RPC. In this method instead of loading the plugins into the host process we load them in a separate process which then communicates to host via RPC or just TCP on localhost. It has several important upsides:</p><ul><li>Isolation: crash in a plugin does not bring the whole application down.</li><li>Interoperability between languages: if RPC is the interface, do you care what language the plugin is written in?</li><li>Distribution: if plugins interface via the network, we can easily distribute them to run on different machines for gains in performance, reliability, and so on.</li></ul><p id="f78c">Moreover, Golang makes this particularly easy by having a fairly capable RPC package right in the standard library: net/rpc.</p><p id="4495">One of the most widely used RPC-based plugin systems is <a href="https://github.com/hashicorp/go-plugin">hashicorp/go-plugin</a>. Hashicorp is well known for creating great Golang software, and apparently, they use go-plugin for many of their systems, so it’s battle-tested (though its documentation could be better 😛)</p><p id="1a23">Golang-plugin runs on top of net/rpc but also supports gRPC. Advanced RPC protocols like gRPC are well suitable for plugins because they include versioning out-of-the-box, tackling the difficult interoperability problem between different versions of plugins vs. the main application.</p><p id="c8a4">However, this is also<b> not a perfect solution </b>as we talk about the fourth fundamental of plugin systems- “<b>Extension APIs</b>”. In a complex system, a plugin might make lot of Extension APIs calls which will end up increasing the latency if we are making network calls via RPC or TCP.</p><h1 id="1c76">Conclusion</h1><p id="03fb">Golang still has a long way to go when it comes to Dynamic-linking (shared library plugins). No solution discussed in this blog can be considered perfect. One needs to consider the pros and cons of each solution available as per their specific requirements.</p></article></body>

ASMR: What’s it all About?

This odd brain trick works wonders for mental health.

Photo by Icons8 on Unsplash

In my last article, I discussed how this pandemic-inflicted social isolation is making us increasingly “touch-starved.” Modern society was already becoming increasingly distant (meaning our mental health was already paying the price), and then COVID-19 hit and we knew the try meaning of isolation…

And so, I have already established that human contact is profoundly important for both mental and physical health. From affecting our hormone levels to stabilizing our blood pressure, human contact does a lot more than help to ease loneliness. It is actually a fundamental part of our health.

One tip I mentioned when it comes to mimicking the sensory and biological reaction to human touch was to try out ASMR. But I feel I needed to shed a little more light on this still little-understood phenomenon and how it can be a real life-saver — especially given the current circumstances.

Some describe it as a “braingasm”, “brain butterflies” or simply as tingles starting at the back of the head…

What is ASMR?

I’ll bet you’ve tried at least one type of therapy — even if not in the traditional one-on-one conversation format — aromatherapy, therapy through touching such as massage, acupuncture or somatic experiencing, mindfulness meditation, yoga, or even therapy through food or contact with animals. Any activity where the main priority was to alleviate a mental or physical pain of some sort.

How lucky we are in this day and age to have such a plethora of potential methods to get out our nervous energy and sink into that crucial state of relaxation.

But what about therapy through sound? Can our ears also be a window to wellness and wellbeing?

Enter: ASMR

ASMR — which stands for Autonomous Sensory Meridian Response — is still a relatively new term. It describes a feeling of euphoric tingling and relaxation that can come over you when you hear certain sounds or receive certain close attention, non-sexual physical touch, or stimuli. Some describe it as a “braingasm”, “brain butterflies” or simply as tingles starting at the back of the head and neck which trickle down the spine. But it seems that only a certain chunk of the human population can experience it — at least organically.

How to intentionally experience ASMR

There are three ways that people can experience ASMR:

  • Organically when you are in certain situations where you may encounter unexpected “unintentional ASMR.” At the hair salon, the doctor’s office, or when someone writes something on your arm, for example.
  • Simple meditation or just thinking about a scene or sound that triggers you. For example, by imagining that you are having a massage, or that someone is brushing your hair.
  • Watching a video or listening to a recording specifically designed to trigger ASMR.

Accidental ASMR triggers are all around us…

Maybe it’s when you go to the hair salon, or when being carefully examined by a healthcare professional — the combination of soft human contact and close personal attention is a common trigger.

Or, if your triggers are more sound-oriented, maybe you get it when you hear the light tapping of rain on the window, the crackling of a fire, or soft distant murmurs down the hallway. A strange feeling of tingling comfort — both stimulating and sedative simultaneously.

Some people get it when they witness someone closely concentrating on or examining something — maybe watching somebody write or draw quietly, type on their keyboard, or when somebody reads or observes something of yours. These are empathetic triggers that are even more baffling to experts to explain biologically…

There are many common triggers, and others that seem more unique to an individual. Overall, they seem to share the common thread of being associated with gentle sensory stimulation and/ or close personal attention — either to themselves or to a third party.

Nowadays, as with most things, the internet has stepped in to give you access to this sensation whenever you want. There is a huge and ever-growing range of ASMR videos on YouTube, recordings on Spotify, and even apps specifically intended for ASMR such as Tingles.

On these recordings, you might hear someone’s voice speaking or whispering, the sound of hair being brushed or trimmed, light scratching of a pencil on paper, or other triggers mentioned previously such as the rain or fire crackling. They have the primary intention of sparking this ASMR response in their consumers. And their popularity has only continued to surge in the past few years — going from odd niche to a widely appreciated and in-demand genre.

ASMR: The self-care hack we all need?

ASMR for sleep

ASMR can induce relaxation before bedtime, which can help you overcome insomnia. In fact, most ASMR videos you can find online have inducing sleep as their main purpose. Some “ASMRtists” will intentionally whisper you to sleep, while other videos will use various types of white noise to lure you into a deep slumber. Since most people with sleep problems blame their racing thoughts for their lack of shut-eye, ASMR could be just the ticket to let the mind trail off into a state of calm and peace, allowing you to put your worries to bed too.

ASMR for focus

On the reverse side, you can actually use ASMR to help you focus on a task. For instance, if you are working on an essay piece of artwork, listening to an ASMR clip can be an effective switch to your usual playlist. Many of us don’t like complete silence while we are working, but also find that most music — although it may make an otherwise boring and sensorily barren couple of hours a little more enjoyable — can be distracting. ASMR stimulates your senses more than even your favorite tracks could — and yet doesn’t complete with the task at hand for your attention.

ASMR for anxiety & depression

ASMR is also a powerful soother for those prone to anxiety or depression. The same way it can quieten a chatty mind to help you drift off, it can also lift your mood and calm you down.

If anxiety is your poison, then however these intrusive thoughts and constant worry are manifested, by incorporating ASMR into your self-care routine, you may well notice that you been generally calmer and that any compulsions begin to fade.

When it comes to depression, just as human contact and personal attention can soothe a depressed soul by reminding you that you are a valuable human being, ASMR can mimic this sense of closeness even when no one is around. The little mood lift you get from the pleasant sensations which arise from the soft sounds can be the first nudge out of a dark mental place.

ASMR for meditation

ASMR can be used as an alternative to traditional meditation as a way to achieve a relaxed, meditative state. Although ASMR recordings range from roleplays to whispered ramblings, the non-verbal triggers, in particular, can be an effective way to quieten the mind, focus on nothing but the present and your own physical sensations, and temporarily separate yourself from the stresses of the world around you.

ASMR: The Bottom Line

Since ASMR doesn’t work for everyone, it can be tough to imagine the sensation if you have never— or at least, haven’t yet — experienced it first-hand. Although what exactly is going on inside our heads when we experience ASMR is yet to be determined, when we look at the most common triggers — personal attention, someone else’s concentration on a task, and the feeling of being somewhere safe and comforted — there’s a lot to unpack.

Maybe this stems from our tribal roots. We take incomparable pleasure in close companionship — which was historically demonstrated through grooming or friendly physical contact. It could also be a biological nostalgia from our infancy, from recreating the warm fuzzy feeling of being closely held, and the sense of security we once got from watching our guardians carry out mundane tasks such as writing, or folding laundry.

Could ASMR, then, be the ticket to combatting touch starvation and sensory deprivation many of us have been facing during the lockdown? Could this replica of human affection or the soft touch of nature really replicate the sense of comfort we get from the real thing? It may seem unlikely, but for many, it really does! And it can be a great way to calm anxiety, alleviate symptoms of depression, and increase your overall sense of mental and emotional wellbeing.

Roxanna is a British-Iranian content writer specialized in human rights, identities, health, and welfare. With a languages degree from King’s College London, a Master’s degree in European Studies from LSE, and a background in political PR, she strives to increase visibility and encourage debate around ethical, psychological, and sociocultural issues around the world. http://roxannaazimy.com Twitter: @roxannayasmin

Anxiety
Depression
Asmr
Self Care
Mental Health
Recommended from ReadMedium