Cloud-oriented Life

Cloud Native Technology Improves Lives

paranoia or acts_as_paranoid

paranoia is a re-implementation of acts_as_paranoid for Rails 3/4/5, using much, much, much less code.

When your app is using Paranoia, calling destroy on an ActiveRecord object doesn’t actually destroy the database record, but just hides it. Paranoia does this by setting a deleted_at field to the current time when you destroy a record, and hides it by scoping all queries on your model to only include records which do not have a deleted_at field.

Read more »

FAQs about Docker Containers or Kubernetes (K8S) Pods

Exit Code: 137

A Pod is terminated or restarted with exit code 137. It should happen Out Of Memory(OOM).

Run kubectl describe pod command to check pod state.

1
2
3
4
5
6
7
8
9
10
11
12
# kubectl describe pod <name>
...
State: Running
Started: Feb, 03 Sep 2020 02:46:17 +0800
Last State: Terminated
Reason: Error
Exit Code: 137
Started: Sat, 01 Feb 2020 11:32:03 +0800
Finished: Mon, 03 Feb 2020 02:46:12 +0800
Ready: True
Restart Count: 1
...

Run journalctl command to check journal logs.

1
2
3
4
5
6
7
8
9
10
11
# journalctl -k | grep -i -e memory -e oom
Feb 03 02:46:14 s1 kernel: [<ffffffff81bbb076>] out_of_memory+0x4b6/0x4f0
Feb 03 02:46:14 s1 kernel: [ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name
Feb 03 02:46:15 s1 kernel: Out of memory: Kill process 22739 (bundle) score 1325 or sacrifice child
Feb 03 02:46:15 s1 kernel: kthreadd invoked oom-killer: gfp_mask=0x3000d0, order=2, oom_score_adj=0
Feb 03 02:46:15 s1 kernel: [<ffffffffc03cb71a>] ? virtballoon_oom_notify+0x2a/0x70 [virtio_balloon]
Feb 03 02:46:15 s1 kernel: [<ffffffff81bba834>] oom_kill_process+0x254/0x3d0
Feb 03 02:46:15 s1 kernel: [<ffffffff81bba2dd>] ? oom_unkillable_task+0xcd/0x120
Feb 03 02:46:15 s1 kernel: [<ffffffff81bbb076>] out_of_memory+0x4b6/0x4f0
Feb 03 02:46:15 s1 kernel: [ pid ] uid tgid total_vm rss nr_ptes swapents oom_score_adj name
Feb 03 02:46:15 s1 kernel: Out of memory: Kill process 23056 (util.rb:22) score 1326 or sacrifice child

nil?, empty?, blank?, and present?

Ruby and Rails have several methods that can be used to check for the existence of a value or the state of an object. Ruby provides #nil? and #empty?, and Rails’ ActiveSupport adds #blank? and #present?. All these work in their own way and it’s important to know how each evaluates data as using the wrong method in your code might cause unexpected results.

In this article, we’ll refresh your knowledge on these methods. We’ll (re)learn what conditions pass or fail when each is used as well as the type of objects each method can be used on. We’ll even throw in a handy cheat sheet at the end!

Read more »

Joins vs Preload vs Includes vs Eager load

Rails ActiveRecord provide few ways to load associated data and before moving forward.

let’s consider one scenario as below, there is a User table that has a one-to-many association with the Post table.

Read more »

Rails Cache

Caching means to store content generated during the request-response cycle and to reuse it when responding to similar requests.

Caching is often the most effective way to boost an application’s performance. Through caching, web sites running on a single server with a single database can sustain a load of thousands of concurrent users.

Rails provides a set of caching features out of the box. This guide will teach you the scope and purpose of each one of them. Master these techniques and your Rails applications can serve millions of views without exorbitant response times or server bills.

Read more »
0%