반응형

출처 : https://stackoverflow.com/questions/9768444/possible-eventemitter-memory-leak-detected

가능한 EventEmitter 메모리 누수 감지됨

다음 warning이 나왔습니다.

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
    at EventEmitter.<anonymous> (events.js:139:15)
    at EventEmitter.<anonymous> (node.js:385:29)
    at Server.<anonymous> (server.js:20:17)
    at Server.emit (events.js:70:17)
    at HTTPParser.onIncoming (http.js:1514:12)
    at HTTPParser.onHeadersComplete (http.js:102:31)
    at Socket.ondata (http.js:1410:22)
    at TCP.onread (net.js:354:27)

저는 server.js에 다음처럼 코드를 작성하였습니다.

http.createServer(
    function (req, res) { ... }).listen(3013);

이를 어떻게 고칠 수 있을까요?


21개의 답변 중 3개의 답변

이것은 노드 eventEmitter 문서에 설명되어 있습니다.

노드의 버전은 무엇입니까? 어떤 다른 코드가 있습니까? 정상적인 행동이 아닙니다.

간단히 말해서: process.setMaxListeners(0);

또한 다음도 참조하세요: node.js - 요청 - "emitter.setMaxListeners()" 방법?


경고가 있는 데는 이유가 있으며 올바른 수정이 제한을 늘리지 않고 동일한 이벤트에 그렇게 많은 리스너를 추가하는 이유를 알아내는 좋은 기회가 있음을 여기서 지적하고 싶습니다. 왜 그렇게 많은 리스너가 추가되고 있는지 알고 있고 그것이 정말로 원하는 것이라고 확신하는 경우에만 제한을 늘리십시오.

이 경고를 받았기 때문에 이 페이지를 찾았고 제 경우에는 전역 개체를 EventEmitter로 바꾸는 버그가 사용 중이었기 때문에 이 페이지를 찾았습니다! 이러한 것들이 눈에 띄지 않게 하고 싶지 않기 때문에 전 세계적으로 한도를 늘리지 않는 것이 좋습니다.


기본으로 최대 10개의 listener가 하나의 이벤트마다 등록될 수 있습니다.

다음이 당신의 코드라면 maxListeners를 다음을 통해 지정할 수 있습니다.

const emitter = new EventEmitter()
emitter.setMaxListeners(100)
// 0은 한계를 제한하지 않습니다.
emitter.setMaxListeners(0)

만약 다음이 당신의 코드가 아니라면 당신은 전역으로 그 수를 늘릴 수 있습니다.

require('events').EventEmitter.prototype._maxListeners = 100;

당연히 당신은 한계를 없앨 수 있지만 주의해야 합니다.

// 기본으로 한계를 없앤다. (주의하세요.)
require('events').EventEmitter.prototype._maxListeners = 0;

추신. 코드는 당신의 응용프로그램의 아주 시작에 와야 합니다.

추가: node 0.11부터 이는 기본 한계를 변경하여 작동합니다.

require('events').EventEmitter.defaultMaxListeners = 0
반응형
반응형

출처 

https://mariadb.com/kb/en/mariadb/memory-storage-engine/



MEMORY 저장 엔진

MEMORY Storage Engine


(이전엔 HEAP으로 알려진) MEMORY 저장 엔진의 내용은 디스크보다 메모리에 보관됩니다.


Contents of the MEMORY storage engine (previously known as HEAP) are stored in memory rather than on disk.


다른 테이블로부터 데이터의 읽기전용 캐쉬 즉 임시적인 작업 영역에서 사용하는 데 최고입니다.


It is best-used for read-only caches of data from other tables, or for temporary work areas.


데이터가 메모리에 보관되기 때문에 정전이나 하드웨어 고장에 매우 취약하며 영원히 데이터를 보관하는 데는 적절하지 않습니다. 사실, 서버가 재시작 하면 MEMORY 테이블은 (정의 파일이 디스크에 저장되기 때문에) 재생성 되지만 그 내용은 비어있을 것입니다. --init-file 서버 시작(startup) 옵션을 사용하여 쿼리로 원하는 내용을 다시 채울 수 있습니다.


Since the data is stored in memory, it is highly vulnerable to power outages or hardware failure, and is unsuitable for permanent data storage. In fact, after a server restart, MEMORY tables will be recreated (because the definition file is stored on disk), but they will be empty. It is possible to re-populate them with a query using the --init-file server startup option.


VARCHAR 같은 변수-길이 타입은 MEMORY 테이블에서 사용될 수 있습니다. BLOB 또는 TEXT 열(column)은 MEMORY 테이블에서 지원되지 않습니다.


 Variable-length types like VARCHAR can be used in MEMORY tables. BLOB or TEXT columns are not supported for MEMORY tables.


MEMORY 테이블의 최대 총 용량은 max_heap_table_size 시스템 서버 변수를 넘어설 수 없습니다. 테이블이 만들어질 때 이 값은 그 테이블에 적용하며, 서버가 재시작될 때 이 값은 현재 있는 테이블에 적용합니다. 이 값을 바꾸는 것은 현재 있는 테이블에는 효과가 없습니다. 하지만 ALTER TABLE ... ENGINE=MEMORY 문장의 실행은 그 테이블의 max_heap_table_size의 현재 값을 적용합니다. 또한 테이블을 만들기 전에 max_heap_table_size의 세션 값을 변경하는 것이 가능합니다.


 The maximum total size of MEMORY tables cannot exceed the max_heap_table_size system server variable. When a table is created this value applies to that table, and when the server is restarted this value applies to existing tables. Changing this value has no effect on existing tables. However, executing a ALTER TABLE ... ENGINE=MEMORY statement applies the current value ofmax_heap_table_size to the table. Also, it is possible to change the session value of max_heap_table_size before creating a table, to make sure that tables created by other sessions are not affected.


MAX_ROWS 테이블 옵션은 당신이 테이블에 저장할 행수에 관해 힌트를 제공합니다. 이 값은 초과할 수 없는 한계는 없지만, max_heap_table_size를 넘어설 수 없습니다. 저장 엔진은 테이블에 할당된 최대 메모리를 계산하는 데 max_heap_table_size와 MAX_ROWS를 사용합니다.


 The MAX_ROWS table option provides a hint about the number of rows you plan to store in them. This is not a hard limit that cannot be exceeded, and does not allow to exceed max_heap_table_size. The storage engine uses max_heap_table_size and MAX_ROWS to calculate the maximum memory that could be allocated for the table.


행이 삭제되었을 때 그 공간은 자동으로 해제되지 않습니다. 테이블을 없애지(drop) 않고 공간을 해제하는 유일한 방법은 ALTER TABLE tbl_name ENGINE = MEMORY 를 사용하는 것입니다. TRUNCATE TABLE도 메모리를 해제합니다.


 When rows are deleted, space is not automatically freed. The only way to free space without dropping the table is usingALTER TABLE tbl_name ENGINE = MEMORY

TRUNCATE TABLE frees the memory too.


인덱스 타입

Index type


MEMORY 저장 엔진은 B-tree 또는 Hash 인덱스를 허용합니다. 해시는 MEMORY에 대한 기본 타입 입니다. 보관 엔진 인덱스 타입을 보시면 더 많은 성질들을 확인할 수 있습니다.


The MEMORY storage engine permits indexes to be either B-tree or Hash. Hash is the default type for MEMORY. See Storage Engine index types for more on their characteristics.


MEMORY 테이블은 64개의 인덱스까지, 각 인덱스당 16개의 열(column)과 최대 키의 길이는 3072바이트까지 가질 수 있습니다.


A MEMORY table can have up to 64 indexes, 16 columns for each index and a maximum key length of 3072 bytes.

추가 보기

See also

 

 


예시

Example

다음 예시는 위에서 묘사된 주어진 최대 크기로 MEMORY 테이블을 만드는 방법을 보여줍니다.

The following example shows how to create a MEMORY table with a given maximum size, as described above.


반응형

'번역' 카테고리의 다른 글

테스트 주도 개발  (0) 2016.01.22
Computer virus  (0) 2009.10.07
악성코드  (0) 2009.10.07
BHO  (0) 2009.10.07
행성의 정의  (0) 2009.08.03

+ Recent posts