Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
7a3df0a1
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7a3df0a1
编写于
4月 05, 2019
作者:
A
andy finch
提交者:
Ryan Dahl
4月 05, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add worker benchmarks (#2059)
上级
031411b4
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
139 addition
and
3 deletion
+139
-3
js/workers.ts
js/workers.ts
+8
-1
tests/subdir/bench_worker.ts
tests/subdir/bench_worker.ts
+20
-0
tests/workers_round_robin_bench.ts
tests/workers_round_robin_bench.ts
+75
-0
tests/workers_startup_bench.ts
tests/workers_startup_bench.ts
+25
-0
tools/benchmark.py
tools/benchmark.py
+2
-0
website/benchmarks.html
website/benchmarks.html
+9
-2
未找到文件。
js/workers.ts
浏览文件 @
7a3df0a1
...
...
@@ -150,11 +150,13 @@ export interface Worker {
onmessage
?:
(
e
:
{
data
:
any
})
=>
void
;
onmessageerror
?:
()
=>
void
;
postMessage
(
data
:
any
):
void
;
closed
:
Promise
<
void
>
;
}
export
class
WorkerImpl
implements
Worker
{
private
readonly
rid
:
number
;
private
isClosing
:
boolean
=
false
;
private
readonly
isClosedPromise
:
Promise
<
void
>
;
public
onerror
?:
()
=>
void
;
public
onmessage
?:
(
data
:
any
)
=>
void
;
public
onmessageerror
?:
()
=>
void
;
...
...
@@ -162,11 +164,16 @@ export class WorkerImpl implements Worker {
constructor
(
specifier
:
string
)
{
this
.
rid
=
createWorker
(
specifier
);
this
.
run
();
hostGetWorkerClosed
(
this
.
rid
).
then
(()
=>
{
this
.
isClosedPromise
=
hostGetWorkerClosed
(
this
.
rid
);
this
.
isClosedPromise
.
then
(()
=>
{
this
.
isClosing
=
true
;
});
}
get
closed
():
Promise
<
void
>
{
return
this
.
isClosedPromise
;
}
postMessage
(
data
:
any
):
void
{
hostPostMessage
(
this
.
rid
,
data
);
}
...
...
tests/subdir/bench_worker.ts
0 → 100644
浏览文件 @
7a3df0a1
onmessage
=
function
(
e
)
{
const
{
cmdId
,
action
,
data
}
=
e
.
data
;
switch
(
action
)
{
case
0
:
// Static response
postMessage
({
cmdId
,
data
:
"
HTTP/1.1 200 OK
\r\n
Content-Length: 12
\r\n\r\n
Hello World
\n
"
});
break
;
case
1
:
// Respond with request data
postMessage
({
cmdId
,
data
});
break
;
case
2
:
// Ping
postMessage
({
cmdId
});
break
;
case
3
:
// Close
workerClose
();
break
;
}
};
tests/workers_round_robin_bench.ts
0 → 100644
浏览文件 @
7a3df0a1
// Benchmark measures time it takes to send a message to a group of workers one
// at a time and wait for a response from all of them. Just a general
// throughput and consistency benchmark.
const
data
=
"
HTTP/1.1 200 OK
\r\n
Content-Length: 12
\r\n\r\n
Hello World
\n
"
;
const
workerCount
=
4
;
const
cmdsPerWorker
=
400
;
export
interface
ResolvableMethods
<
T
>
{
resolve
:
(
value
?:
T
|
PromiseLike
<
T
>
)
=>
void
;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
reject
:
(
reason
?:
any
)
=>
void
;
}
export
type
Resolvable
<
T
>
=
Promise
<
T
>
&
ResolvableMethods
<
T
>
;
export
function
createResolvable
<
T
>
():
Resolvable
<
T
>
{
let
methods
:
ResolvableMethods
<
T
>
;
const
promise
=
new
Promise
<
T
>
((
resolve
,
reject
)
=>
{
methods
=
{
resolve
,
reject
};
});
// TypeScript doesn't know that the Promise callback occurs synchronously
// therefore use of not null assertion (`!`)
return
Object
.
assign
(
promise
,
methods
!
)
as
Resolvable
<
T
>
;
}
function
handleAsyncMsgFromWorker
(
promiseTable
:
Map
<
number
,
Resolvable
<
string
>>
,
msg
:
{
cmdId
:
number
;
data
:
string
}
):
void
{
const
promise
=
promiseTable
.
get
(
msg
.
cmdId
);
if
(
promise
===
null
)
{
throw
new
Error
(
`Failed to find promise: cmdId:
${
msg
.
cmdId
}
, msg:
${
msg
}
`
);
}
promise
.
resolve
(
data
);
}
async
function
main
():
Promise
<
void
>
{
const
workers
:
Array
<
[
Map
<
number
,
Resolvable
<
string
>>
,
Worker
]
>
=
[];
for
(
var
i
=
1
;
i
<=
workerCount
;
++
i
)
{
const
worker
=
new
Worker
(
"
tests/subdir/bench_worker.ts
"
);
const
promise
=
new
Promise
(
resolve
=>
{
worker
.
onmessage
=
e
=>
{
if
(
e
.
data
.
cmdId
===
0
)
resolve
();
};
});
worker
.
postMessage
({
cmdId
:
0
,
action
:
2
});
await
promise
;
workers
.
push
([
new
Map
(),
worker
]);
}
// assign callback function
for
(
const
[
promiseTable
,
worker
]
of
workers
)
{
worker
.
onmessage
=
e
=>
{
handleAsyncMsgFromWorker
(
promiseTable
,
e
.
data
);
};
}
for
(
const
cmdId
of
Array
(
cmdsPerWorker
).
keys
())
{
const
promises
:
Array
<
Promise
<
string
>>
=
[];
for
(
const
[
promiseTable
,
worker
]
of
workers
)
{
const
promise
=
createResolvable
<
string
>
();
promiseTable
.
set
(
cmdId
,
promise
);
worker
.
postMessage
({
cmdId
:
cmdId
,
action
:
1
,
data
});
promises
.
push
(
promise
);
}
for
(
const
promise
of
promises
)
{
await
promise
;
}
}
for
(
const
[,
worker
]
of
workers
)
{
worker
.
postMessage
({
action
:
3
});
await
worker
.
closed
;
// Required to avoid a cmdId not in table error.
}
console
.
log
(
"
Finished!
"
);
}
main
();
tests/workers_startup_bench.ts
0 → 100644
浏览文件 @
7a3df0a1
// Benchmark measures time it takes to start and stop a number of workers.
const
workerCount
=
50
;
async
function
bench
():
Promise
<
void
>
{
const
workers
:
Worker
[]
=
[];
for
(
var
i
=
1
;
i
<=
workerCount
;
++
i
)
{
const
worker
=
new
Worker
(
"
tests/subdir/bench_worker.ts
"
);
const
promise
=
new
Promise
(
resolve
=>
{
worker
.
onmessage
=
e
=>
{
if
(
e
.
data
.
cmdId
===
0
)
resolve
();
};
});
worker
.
postMessage
({
cmdId
:
0
,
action
:
2
});
await
promise
;
workers
.
push
(
worker
);
}
console
.
log
(
"
Done creating workers closing workers!
"
);
for
(
const
worker
of
workers
)
{
worker
.
postMessage
({
action
:
3
});
await
worker
.
closed
;
// Required to avoid a cmdId not in table error.
}
console
.
log
(
"
Finished!
"
);
}
bench
();
tools/benchmark.py
浏览文件 @
7a3df0a1
...
...
@@ -25,6 +25,8 @@ exec_time_benchmarks = [
(
"error_001"
,
[
"tests/error_001.ts"
]),
(
"cold_hello"
,
[
"tests/002_hello.ts"
,
"--reload"
]),
(
"cold_relative_import"
,
[
"tests/003_relative_import.ts"
,
"--reload"
]),
(
"workers_startup"
,
[
"tests/workers_startup_bench.ts"
]),
(
"workers_round_robin"
,
[
"tests/workers_round_robin_bench.ts"
]),
]
gh_pages_data_file
=
"gh-pages/data.json"
...
...
website/benchmarks.html
浏览文件 @
7a3df0a1
...
...
@@ -29,11 +29,18 @@
href=
"https://github.com/denoland/deno/blob/master/tests/002_hello.ts"
>
tests/002_hello.ts
</a>
and
</a>
,
<a
href=
"https://github.com/denoland/deno/blob/master/tests/003_relative_import.ts"
>
tests/003_relative_import.ts
</a
>
,
<a
href=
"https://github.com/denoland/deno/blob/master/tests/worker_round_robin_bench.ts"
>
tests/worker_round_robin_bench.ts
</a
>
, and
<a
href=
"https://github.com/denoland/deno/blob/master/tests/worker_startup_bench.ts"
>
tests/worker_startup_bench.ts
</a
>
. For deno to execute typescript, it must first compile it to JS. A
warm startup is when deno has a cached JS output already, so it should
be fast because it bypasses the TS compiler. A cold startup is when deno
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录