2012년 6월 30일 토요일

JavaScript Web Applications (한빛미디어)




이 책은 자바스크립트 애플리케이션 개발 시 유용한 아키텍쳐 패턴인 MVC 패턴을 소개하고, 이 패턴을 애플리케이션에 적용하는 데 도움을 주는 여러 모듈의 사용 방법 및 테스트를 위한 프레임워크 그리고 HTML5의 파일API, 웹소켓에 대해서 다루고 있습니다.

이제는 웹 애플리케이션이 단순히 서버에서 제공하는 정보를 보여주는 것이 아니라 클라이언트에서 복잡한 연산과 로컬 데이터 생성 및 관리가 필요하게 되었습니다. 곧 네이티브 어플리케이션이 하는 작업을 웹 애플리케이션에서도 수행을 할 수 있게 된것인데, 이는 웹 프로그램도 네이티브 프로그램처럼 복잡해진다는 것을 의미합니다. 따라서 구조화된 개발이 필요하게 되었고, 이 책은 MVC 패턴으로 웹 애플리케이션을 구조화를 할 수 있도록 모델, 컨트롤러, 뷰 컴포넌트에 대해 아주 자세히 설명하고 있습니다. 책 후반부에서는 이 패턴 사용에 필요한 라이브러리인 스파인, 백본, 자바스크립트MVC 라이브러리를 다루고, 간단한 애플리케이션 예제를 통해 라이브러리를 어떻게 활용하는지 설명하고 있습니다. 또한 프로그램이 커져가면서 자연히 의존하는 모듈이 늘어가게 되는데 이러한 의존성을 관리하는 방법을 다루고 있습니다.

이 책의 서두에서 대상독자는 자바스크립트 초보자가 대상이 아니라고 말하고 있지만, 정말 쌩초보(?)가 아니라면 이책을 권하고 싶습니다. 본격적인 개발경험을 하기 전에 이 책을 통해 유용한 자바스크립트 아키텍쳐 패턴인 MVC 패턴에 대해 알고 익힐 수 있다면 실제 개발에 큰 도움이 될 것입니다. 
자바스크립트를 쓸 줄 아는 개발자에서 자바스크립트를 잘! 쓸 수 있는 개발자로 변신하고 싶다면 꼭 이책을 읽기를 바랍니다.

2012년 6월 23일 토요일

About Renderer process


How browser process manages the number of renderer process?

As you may know, chromium has multi process architecture. In this architecture many renderer processes are running. You can see many renderer processes running by ps command(in linux) or task manager(in Windows) When we use chromium browser, many renderer processes are created and destroyed. It lives long or very short depends on the situation.
In this document, I’ll cover two topics. First one is when new renderer process is created. Second is how the number of renderer processes are controlled.

Topic 1. When renderers are created and destroyed?

1. At start time

When user execute chromium, new renderer is created with new tab. If only one tab is opened, one renderer is created. If many tabs are opened, many renderers are created. The number of renderer process depends on installed system memory and --renderer-process-limit option. The number of renderer process will be covered second section.

2.  Type new url to omnibox of opened tab

When user types new url, whether new renderer process is created or not is depends on below two options.
*process-per-site-instance
This is a current default process model. If user don’t add either process-per-site or process-per-tab, this mode is used. When you type new url to current tab, renderer is replaced.
I’m curious about separate visits to the same site on the same tab. Sometime, renderer process is replaced in this case.
In this mode, different tabs have different renderer regardless of its domain.
* process-per-site
If you type url that have different domain to current tab, new renderer is created for current tab. And old renderer is destroyed. Otherwise(typed url that have same domain), existing renderer is used for rendering new url.
  ex1) Current tab is in www.google.com and you type gmail.google.com, current renderer is
           used because two url have same domain(google.com).
  ex2) Current tab is in www.google.co.kr and you type gmail.google.com, current renderer is
          destroyed and new renderer process is launched because two url has different domain.
In this mode,  many tabs that have same domains are grouped in a renderer.
* process-per-tab
When user add this switch value, one renderer process is used before the tab is closed. I found that this mode has some bug when I enabled low-memory-observer.

3. Add new tab

When user clicks new tab button, NTP(New Tab Page) that show most visited pages or installed webapp is created.  Opening many NTP sequentially don’t  create renderer process. When user insert url on the NTP, new renderer is also created if renderer limit is not exceeded. If user types new url or click page snap, new renderer is created and existed renderer is destroyed. This behavior also depends --process-per-tab or --process-per-site.

4. OOM Handler (chromeos)

When browser process receive oom event from kernel’s low-mem notifier, browser process choose least recently used tab’s renderer process. And that renderer is discarded.

Topic 2. How many renderers are created?


As I mentioned earlier, you can see many renderers. The number of tabs is not equals the number of renderer process. In this topic, I’ll explain what determines the number of renderer process

1.  --renderer-process-limit=N

Browser process only creates renderer process up to N. When new tab is created, RenderProcessHost checks whether this switch is used.

2. --single-process

Browser process don’t create renderer process if this is on.

3. Installed system memory

If above switches are not used, max number of renderer process is calculated based on installed system memory not available memory.
You can see the formula that calculates the max number of renderer process in the RenderProcessHost::GetMaxRendererProcessCount().

4. The number of Extension service process

If there is a room to create another renderer process, chromium considers running extension service. Browser process don’t create renderer if extension service process number is bigger than max number of render process * 0.3.
Refer to ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost().

5. Click the link

When user clicks url link with target attribute ‘_blank’, new tab is created for that link. But, browser process don’t create new renderer process and share its parent’s renderer process. When I click many links from same webpage, only one renderer is used for all created tabs.