Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
怖くないメモリ肥大化
Search
Tsukasa OISHI
October 31, 2024
Programming
1
49
怖くないメモリ肥大化
Nihonbashi.js #9のLTで発表しました。
Node.jsでのメモリ肥大化にどう対応するかというお話です。
Tsukasa OISHI
October 31, 2024
Tweet
Share
More Decks by Tsukasa OISHI
See All by Tsukasa OISHI
SLI/SLO をストリーム アラインドチームに導入した話
tsukasa_oishi
0
140
JITをたどるとそこはYARVの中
tsukasa_oishi
0
550
The Cacher in the Rye
tsukasa_oishi
1
5.7k
ISeqで遊ぼう
tsukasa_oishi
0
5k
Rubyを30倍速くした話
tsukasa_oishi
0
1.1k
はてブ砲をくらったときのお話
tsukasa_oishi
0
1.9k
食べログで動いている自作ライブラリのお話
tsukasa_oishi
0
290
奥さんとプログラミングを両立させる方法
tsukasa_oishi
0
50
MiyazakiResistanceを作ってみたよ
tsukasa_oishi
0
880
Other Decks in Programming
See All in Programming
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
560
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.8k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Jakarta EE meets AI
ivargrimstad
0
300
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
240
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
4
1.1k
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
290
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
230
Click-free releases & the making of a CLI app
oheyadam
2
110
ヤプリ新卒SREの オンボーディング
masaki12
0
120
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Statistics for Hackers
jakevdp
796
220k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
630
A designer walks into a library…
pauljervisheath
202
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Gamification - CAS2011
davidbonilla
80
5k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Bash Introduction
62gerente
608
210k
Transcript
ා͘ͳ͍ ϝϞϦංେԽ
͓͓͍͔ͭ͠͞ !UTVLBTB@PJTIJ
'"5"-&33033FBDIFEIFBQMJNJU"MMPDBUJPOGBJMFE +BWB4DSJQUIFBQPVUPGNFNPSZ
ຊ൪͚ͩى͜ Δ
None
ຊ൪ͰϓϩϑΝ ΠϦϯά͢Δ͠ ͔ͳ͍
IUUQT[FOOEFWVCJF@EFWBSUJDMFTCGBFGF
͍͍ͩͨͷॴΛ ݟ͚ͭΔͷ͕ Ұ൪େมͳͷͰ ͜͜ΛΫϦΞͰ͖ͨΒ ͋ͱॗʑͱΔ͚ͩ
ᶃ
ςετ Λॻ͘
ᶄ
ίʔυ ΛಡΉ
($͕͔͔Βͳ͍ύλʔϯ
const cache: Map<string, any> = new Map(); άϩʔόϧมʹେ͖ͳσʔλঃʑʹ૿͑ΔσʔλΛ࣋ͨͤΔ
($͕͔͔ΔલʹώʔϓΛѹഭ͢Δύλʔϯ
ϧʔϓॲཧͰେྔͳΦϒδΣΫτΛੜ function generateLargeNumberOfObjects() { const objects: { id: number; data:
string }[] = []; for (let i = 0; i < 1000000; i++) { const obj = { id: i, data: ‘aaa….’ }; objects.push(obj); } return objects; }
ΫϩʔδϟʔͰ૿͑ΔσʔλΛอ࣋ function createDataAccumulator() { let data: number[] = []; return
function addData(newData: number): void { data.push(newData); }; } Const accumulateData = createDataAccumulator(); accumulateData(1); accumulateData(2); …
େ͖ͳσʔλΛҰʹѻ͏ const data = fs.readFileSync(filePath, 'utf8');
Կ͔ͷด͡Ε
const connection = mysql.createConnection({…}); connection.query('SELECT * FROM hoge_table’); // connection.end();
ࣗͨͪͷॻ͍ͨίʔυ͕ݪҼͳΒ ͍͍ͩͨίʔυಡΊݟ͔ͭΔ
ࣗͨͪͷॻ͍ͨίʔυͰͳ͍߹ ϓϩϑΝΠϥʔ͕ͳ͍ͱݫ͍͠
ྫ
None
νϟοτͷ ձ͕૿͑Δ ͱΤϥʔ
ɾຊ൪ڥͰͷΈൃੜ͢Δ ɹɾ,T.#ϝϞϦ ɾϩʔΧϧ։ൃڥͰϓϩηεͷϝϞϦݟͯ.#͘Β͍ ɹɾ.BD(#ϝϞϦ '"5"-&33033FBDIFEIFBQMJNJU"MMPDBUJPOGBJMFE +BWB4DSJQUIFBQPVUPGNFNPSZ
($
IFBQPVUPG NFNPSZ
NODE_OPTIONS=—max-old-space-size=250
const chatPrompt = ChatPromptTemplate.fromMessages([ [ "system", "You are a helpful
assistant that translates {input_language} to {output_language}.", ], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", "{text}"], ["human", “{text}"], … ["human", “{text}"], ]);
memoryCheck() { const heap = process.memoryUsage(); const msg = [];
for (const key in heap) { msg.push(`${key}: ${Math.round(heap[key] / 1024 / 1024)} MB`); } console.log(msg.join(', ')); }
start rss: 164 MB, heapTotal: 31 MB, heapUsed: 28 MB
end rss: 1137 MB, heapTotal: 999 MB, heapUsed: 959 MB
ίʔυେৎͦ͏
σόοΨʔ
ৄࡉهࣄʹ͋Γ·͢ IUUQT[FOOEFWVCJF@EFWBSUJDMFTGEE
export async function getEncoding( encoding: TiktokenEncoding, options?: { signal?: AbortSignal;
extendedSpecialTokens?: Record<string, number>; } ) { (লུ) return new Tiktoken( await cache[encoding], options?.extendedSpecialTokens ); }
start rss: 110 MB, heapTotal: 58 MB, heapUsed: 34 MB
end rss: 231 MB, heapTotal: 116 MB, heapUsed: 93 MB
None
·ͱΊ
ϓϩϑΝΠϥʔ Λ͑ΔΑ͏ʹ ͓ͯ͘͠
Α͋͘Δ ύλʔϯ Λ͓ͬͯ͘
࠶ݱςετ ͕ॻ͚Ε ҆৺
͓͠·͍