分类: Uncategorized

  • How to Install Ruby on Debian 10

    Install Ruby on Debian

    Ruby is one of the most popular dynamic and powerful programming languages. Ruby can be used for the development of web applications, games etc. It is mostly used for server-side scripting. It was found in 1993 in Japan. In this tutorial, you are going to learn How to install Ruby on Debian 10.

    There are two ways to install Ruby on Debian and they are:

    1. Install Ruby using Rbenv (recommended)
    2. Install Ruby using Debian Repository

    Prerequisites

    Before you start to install Redis on Debian 10. You must have a non-root user account on your server with sudo privileges.

    Method 1: Install Ruby using Rbenv

    Rbenv is nothing but Ruby version management tool. It is used for switching versions on the same system if multiple versions are installed. To actually Install Ruby we are using here Rbenv plugin ruby-build which is used to install any version easily. Follow the instruction below to install Ruby using Rbenv:

    Now Update the apt package manager index by typing below command:

    sudo apt update

    Install required dependencies for installing rbenv and ruby-build:

    sudo apt install git libreadline-dev zlib1g-dev libreadline-dev libncurses5-dev autoconf bison libssl-dev build-essential libyaml-dev libffi-dev libssl-dev libreadline-dev zlib1g-dev libgdbm-dev

    Navigate to $HOME directory using below command:

    cd

    Next, clone rbenv package typing following command in the terminal:

    git clone https://github.com/rbenv/rbenv.git ~/.rbenv

    After completing the above command, Set the path for rbenv and complete the installation by typing below commands in the terminal one by one:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    exec $SHELL

    Here to install ruby-build plugin for Rbenv run below git command first:

    git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

    After completing above command, Complete the installation and set the path for ruby-build by using below command:

    echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrcCopy
    exec $SHELL

    The current latest stable version for Ruby is 2.6.1 at the time of writing this tutorial. Run below command to install Ruby:

    rbenv install 2.6.1

    Now set the global version on your system running following command using terminal:

    rbenv global 2.6.1

    You should confirm the installation and check the version of Ruby using below command:

    ruby -v

    The output should be following:

    ruby 2.6.1 [x86_64-linux-gnu]

    Method 2: Install Ruby from Debian Repository

    Update the package manager index typing below command in terminal:

    sudo apt update

    Install the Ruby typing following command in terminal:

    sudo apt install ruby-full

    Confirm the installation and check the version using below command:

    ruby -v

    The output should be following:

    ruby 2.6.1 [x86_64-linux-gnu]

    Running a Simple Ruby Program

    Now create and open demo.rb example file using your favourite text editor:

    sudo nano demo.rb

    Copy and paste the following lines inside demo.rb file:

    puts "Welcome to Ruby"

    Save the file and exit the editor using Ctrl+x.

    Next run following command and run demo.rb file:

    ruby demo.rb

    The output should be following:

    Welcome to Ruby

    Conclusion

    You have successfully learned how to install Ruby on Debian 10. If you have any queries please don’t forget to comment out.

  • Eclipse MAT — Incoming, Outgoing References

    Check out the differences between incoming and outgoing references in Eclipse MAT.

    Eclipse Memory Analyzer (MAT) is a powerful tool for heap dump analysis. It has several great features to debug memory problems effectively. ‘Incoming references’ and ‘outgoing references’ are one such feature. In this article, let’s discuss incoming references, outgoing references, and the difference between them.

    In Eclipse MAT, when you right click on any object, you will see drop down menu. If you select ‘List Objects’ menu item, you will notice two options:

    • with outgoing references
    • with incoming references

    As it’s easier to understand new concepts through examples. Let’s learn more about incoming references and outgoing references through an example. Say your application’s source code looks like this:

    public class A {
         private C c1 = C.getInstance();
    }
    public class B {
         private C c2 = C.getInstance();
    }
    public class C {
         private static C myC = new C();
         public static C getInstance() {
                 return myC;
         }
         private D d1 = new D();
         private E e1 = new E();
    }
    public class D {
    }
    public class E {
    }
    public class SimpleExample {
         public static void main (String argsp[]) throws Exception {
                A a = new A();
                B b = new B();
         }
    }

    Now, if we are going draw the objects diagrammatically for the above example application, it’s going to look like this:

    Fig: Sample application’s objects references
    • Object A and Object B are holding a reference to Object C
    • Object C is holding a reference to Object D and Object E

    Now, in this sample project, let’s study the incoming references and outgoing references of object C.

  • 关闭eclipse自动弹出console功能

    使用eclipse时经常会用到最大化窗口,而如果此时是开着tomcat等服务的话,一段后台有打印什么东西出来都会自己弹出 console挺烦人的。可以使用以下操作关闭这个功能。

    Preferences-〉 Run/Debug-〉Console里边 取消勾选 Show when program writes to standard out(当console中有值时弹出)前的选项 和 Show when program writes to standard error(当console中有错误时弹出) 前的选项

  • MAT使用-jvm内存溢出问题排除方法思路

    内存溢出排除方法思路: 

    1.看GC日志  126719K->126719K(126720K) [回收前后内存大小不变或一直增长无减少波动,则可能有内存溢出问题]

    2.生成堆内存 heap dump(某个时间点jvm中所有活跃的对象的堆内存快照)

    3.MAT查看: 过滤列举对象(传入或传出的对象引用)、分组排序显示

    1. Histogram  or dominator_tree: Retained Heap倒叙排序 查看内存占用 

    2. 定位问题代码段:  看有没有GC Root指向:若无GC Root指向 -> Merge Shortest Paths to GC Roots -> exclude all phantom/weak/soft etc.reference(排除虚弱软引用) ->查找GC Root线程

    File > Open Heap Dump > Leak Suspects Report  -打开dump文件

    Overview > Actions > The Histogram (查看堆栈中java类 对象[Objects]个数、[Shallow Heap]individual objects此类对象占用大小、[Retained Heap]关联对象占用大小) -> Retained Heap倒叙排序(重点关注内存占用高对象) ->  Merge Shortest Paths to GC roots ->  exclude all phantom/weak/soft etc.reference(排除所有虚弱软引用) ->查看剩余未被回收的强引用对象占用原因 & GC Roots。

    Overview > Actions > dominator_tree (查看堆中内存占用最高的对象的线程调用堆栈) dominator_tree -> 对象调用堆栈树-查找内存占用最高对象(Retained Heap倒叙排序) ->  Paths to GC Roots -> exclude all phantom/weak/soft etc.reference (排除所有虚弱软引用) -查找GC Root线程 -> 查找未释放的内存占用最高的代码逻辑段(很可能是产生内存溢出代码)

  • Eclipse plugin to automatically refactor Java code bases

    Eclipse plugin to automatically refactor Java code bases