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
Ethereum_.pdf
nekomatu
0
430
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
150
Jakarta EE meets AI
ivargrimstad
0
370
外部システム連携先が10を超えるシステムでのアーキテクチャ設計・実装事例
kiwasaki
1
290
From Subtype Polymorphism To Typeclass-based Ad hoc Polymorphism- An Example
philipschwarz
PRO
0
200
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Contemporary Test Cases
maaretp
0
120
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
300
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
520
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
310
RubyLSPのマルチバイト文字対応
notfounds
0
100
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
KATA
mclloyd
29
14k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Making Projects Easy
brettharned
115
5.9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Gamification - CAS2011
davidbonilla
80
5k
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
·ͱΊ
ϓϩϑΝΠϥʔ Λ͑ΔΑ͏ʹ ͓ͯ͘͠
Α͋͘Δ ύλʔϯ Λ͓ͬͯ͘
࠶ݱςετ ͕ॻ͚Ε ҆৺
͓͠·͍