[컴][웹] React Hooks


React Hooks

Hook 은 거창한 것이 아니다. 이미 class component 에서 제공하던 state 를 function component 에서도 가능하게 해주는 function(?) 라고 보면 된다.

기존의 function component 에서는 state를 사용할 수 없었다.
이 React Hooks 는 아직 정식으로 release 되지 않았다.

Hook 사용시 규칙

Hooks 는 use 로 시작한다. 그리고 facebook 에서도 custom Hook 에 대해서도 이 convention 을 지켜달라고 한다.[ref. 2]

참고로, ref. 3 에 보면 왜 이름을 createState 가 아니라 useState 로 지었는지 이야기가 나온다.
아래 링크를 참고하자.

Hooks FAQ

Hooks 가 어떻게 동작하는가?
How does React associate Hook calls with components?

React keeps track of the currently rendering component. Thanks to the Rules of Hooks, we know that Hooks are only called from React components (or custom Hooks — which are also only called from React components).

There is an internal list of “memory cells” associated with each component. They’re just JavaScript objects where we can put some data. When you call a Hook like useState(), it reads the current cell (or initializes it during the first render), and then moves the pointer to the next one. This is how multiple useState() calls each get independent local state.

References

  1. Introducing Hooks – React
  2. Writing Custom Hooks – React
  3. Using the State Hook – React

[컴][go] golang 의 interface{}(interface type) 의 itable 이 어떻게 생성될까.

golang itable  / how to generate itable in go / go virtual function table /

Go의 itable 의 생성

interface{}(interface type) 에 대한 itable 이 어떻게 생성되는지에 대한 설명이다.

Go 의 dynamic type conversion 들은 compiler 또는 linker 가 미리 모든 가능한 itable 들을 미리계산하는 것이 합리적이지 않다는 뜻이다.

너무 많은 (interface type, concrete type) pair 들이 존재한다. 그리고 대다수는 필요하지 않을 것이다. 대신에, 컴파일러는 위의 예제의 Binary, int 또는 func(map[int]string) 같은 각 concrete type 에 대해서 type description structure 를 생성한다.

비슷하게, 컴파일러는 interface type 에 대해 다른 type description structure 를 하나 생성한다. 그것 또한 method list 를 갖고 있다. interface runtime 은 interface type 의 method table 에 있는 모든 method를 concrete type의 method table 에서 찾아서 itable 을 계산한다.

runtime 은 itable 을 생성한 후에, 이것을 caching 한다. 그래서 이 것은 한번의 계산만 필요하다.


Computing the Itable

Now we know what the itables look like, but where do they come from? Go's dynamic type conversions mean that it isn't reasonable for the compiler or linker to precompute all possible itables: there are too many (interface type, concrete type) pairs, and most won't be needed. Instead, the compiler generates a type description structure for each concrete type like Binary or int or func(map[int]string). Among other metadata, the type description structure contains a list of the methods implemented by that type. Similarly, the compiler generates a (different) type description structure for each interface type like Stringer; it too contains a method list. The interface runtime computes the itable by looking for each method listed in the interface type's method table in the concrete type's method table. The runtime caches the itable after generating it, so that this correspondence need only be computed once. [ref. 1]

References

  1. research!rsc: Go Data Structures: Interfaces
  2. How to use interfaces in Go by jordan orelli

[컴] 윈도우즈10 에 OpenSSH 설치하기

wondows 10 install open ssh


updated, 2020-04-19

  1. Installation of OpenSSH For Windows Server 2019 and Windows 10 | Ms docs, 2019-09-27
위 링크에서 powershell 을 이용해서 바로 windows 에서 제공하는 OpenSSH 를 설치할 수 있다.
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0



윈도우즈10 에 OpenSSH 설치하기

아래 link 에 설명이 나와 있다. 여기서는 Windows 10 version 1803 이전버전에 대한 설치를 진행한다.

설치하기

admin 계정으로 다음 작업들을 한다.

c:\a\apps\oepnssh\win64>powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
[SC] SetServiceObjectSecurity 성공
[SC] ChangeServiceConfig2 성공
[SC] ChangeServiceConfig2 성공
sshd and ssh-agent services successfully installed

c:\a\apps\oepnssh\win64>

그러면 아래처럼 service 가 설치된다.



port 22 열어주기

기본적으로 windows firewall 이 막고 있다. 이것을 열어주자.
powershell 로는 아래처럼 하면 된다.
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22


See Also

  1. Installation of OpenSSH For Windows Server 2019 and Windows 10 | Ms docs, 2019-09-27






[컴][앱][웹] 공유 문서를 local server 에 설치해 보자.

구글독스 / 구글닥스 / google docs in local computer / local server / 로컬서버에서 구글 독스


Etherpad

local server 에서 공동으로 편집이 가능한 editor 이다. 쉽게 생각하면 구글 독스 같은 것을 로컬 서버에 설치해서 사용할 수 있다.





[컴] cpu가 그래픽처리를 위해 GPU를 사용하는 과정



그래픽카드와 함께 CPU 가 좋아야 하는 이유

내용에 틀린부분이 있을 수 있다. 그러니 의심이 가면 관련 부분을 찾아보기 바란다.

일단 단순하게 표현하면, 던전으로 들어가기 전과 후의 장면은 크게 달라진다. 그런데 캐릭터가 던전으로 들어갔는지, 아니면 그 앞까지 왔는지를 결정하는 것은 graphic 부분이 아닌 다른 code 부분이다. GPU 가 graphic 부분의 일을 처리하겠지만, 그 이외의 logic 을 계산하는 것은 cpu 이다. 그러므로 cpu 가 느리다면, 결국 gpu 가 아무리 빨라도 끊김(흔히 버벅임)을 방지하기는 어렵다.


cpu가 그래픽처리를 위해 GPU를 사용하는 과정

The_CUDA_Handbook.pdf 에서 좋은 설명을 확인할 수 있다. 여기선 일부를 정리해 놓았다.

cpu 와 bus



현재까지, 보드의 south bridge가 대부분의 주변기기들을 담당하고, north bridge 가 memory controller 를 가지고 있다. 그래서 이 north bridge 의 memory controller 를 이용해서 cpu 는 memory 와 통신한다.(이 통신이 이뤄지는 interface 가 front-side bus 이다.)

그리고 north bridge 는 gpu 와 PCI Express interface 를 이용해서 통신한다.(물론 pci express 이전에는 AGP 같은 것이 있었다.)

gpu 안에는 gpu memory controller 가 들어가 있다. 그래서 이 memory controller 를 통해 gpu memory 와 통신한다.

Memory controller 가 CPU 안으로

이러다가 cpu 가 memory controller 를 내장했다.(AMD의 Opteron 과 Intel의 Nehalem (i7) ) 그래서 north bridge 없이 바로 memory 와 통신하게 된다.

그리고 I/O Hub 를 통해 PCI express interface 를 사용해서 GPU 에 접근한다.

HyperTransport (HT) / QuickPath Interconnect (QPI) interface

이 상황에서 cpu 를 여러개 사용하기 위해 cpu 간의 통신이 필요했다.(Multiple CPUs (NUMA)) 그래서 생긴것이 HyperTransport (HT) / QuickPath Interconnect (QPI) 이다. 이 interface 로 cpu core 끼리의 통신과 cpu 와 I/O hub 와의 통신을 하게 된다.

  • cpu core <---> cpu core
  • cpu <---> I/O hub

I/O hub 가 CPU 안으로

인텔의 Sandy Bridge 부터 I/O hub 를 cpu 안에 내장하게 된다.




CPU/GPU 연동

The_CUDA_Handbook.pdf 의 2.5 부분의 내용이다.

GPU 는 직접적으로 page-lock 된 CPU memory 에 DMA 를 통해 접근할 수 있다.

Page-locking 은 주변 하드웨어가 CPU Memory 에 직접적으로 접근할 수 있도록 해주기 위해 OS가 사용하는 기능이다.

locked page 들은 OS 에 의해 퇴출(eviction) 에 적합하지 않다고 표시된 상태이다. 그래서 device driver들은 이 주변기기들이 메모리에 직접적으로 접근하기 위해 페이지들의 물리적인 주소들을 이용하라고 프로그램할 수 있다.

CPU 는 여전히 불확실한 상태에서 memory 에 접근할 수 있다. 그러나 메모리는 옮겨지거나, disk 로 paged out 되지 않는다.

DMA 는 GPU 가 CPU memory 를 "cpu 의 실행"에 대해 독립적으로 그리고 병력적으로 read/write 할 수 있게 해줬다. 다만 여기선 race condition 들을 피하기 위해 CPU 와 GPU 사이의 싱크를 맞추는 것을 고려해야 한다.
  • Pinned host memory(pinned buffer): GPU 가 직접 접근할 수 있는 CPU memory 부분
  • Command buffers: GPU 실행을 통제하기 위해 CUDA driver 에 의해 write되고, GPU에 의해 read 되는 buffer. 

pinned buffer

pinned buffer 는 direct access 를 위해 GUP 에 의해 mapping 된다. CUDA 에서는 API cudaMallocHost() 를 통해 allocate 할 수 있다.

pinned buffer 가 주로 사용되는 방법중 하나는 GPU 에 command 를 보내는 용도이다. CPU 가 command 를 buffer 에 write 하고, 동시에 이것을 GPU 가 이전에 write된 command 를 read 하고 execute 한다.

이 buffer 의 앞부분(leading edge) 에 CPU 가 command 를 write 한다. 그래서 GPU 가 이때는 이 녀석을 읽을 수 없다.

GPU 는 buffer 의 끝부분(trailing edge) 에서부터 command 를 읽어드려서 실행한다.

이 command buffer 는 circular queue 라고 보면 된다. 그래서 한번 command 처리를 다한 부분은 다시 CPU 가 command 를 write 하기 위해 사용된다.

cpu-bound / gpu-bound

이 상황에서 2가지 case 가 있는데 CPU-bound 와 GPU-bound 다. bound 는 "경계" 의 뜻이니, CPU bound 는 CPU 가 경계가 되는 경우라고 보면 되고, GPU-bound 는 GPU 가 경계가 되는 것으로 보면 된다.
  • 하나는 CPU 의 command 를 write  < GPU 의 처리 속도(CPU-bound)
  • 하나는 CPU 의 command 를 write  > GPU 의 처리 속도(GPU-bound)


References

[컴][웹] 파이어폭스 검색엔진 추가하기

firefox search engine 추가하기 /


파이어폭스 검색엔진 추가하기

firefox search engine 추가 관련 xml spec.



이 방법은 add-on 을 이용해 바로 firefox 에 search engine 을 추가해 주고 싶을 때 사용하는 방법이다.

xml 을 firefox 에서 인식하는 법



여기에 이 xml 을 어떻게 install 하는지를 알려준다.


web 에서 바로 search engine 추가하기

위에서 만든 xml 의 내용을 아래 web page 에서 바로 입력해서 web page 를 통해 바로 firefox 에 search engine 을 추가할 수 있다.