dart vm - 提高阅读json和http通信的性能

时间:2014-03-14 13:38:58

标签: dart

我正在将dart与nodejs进行比较。

我重写了nodeJs应用程序来解析并返回到http客户端的大块json(大约1000个对象)。出于测试目的,从文件中读取json。然后将json解析为Map,转换为新的表示并响应客户端。

可以在此处找到示例应用mapping json sample app

当我增加对服务的并发呼叫数量时,我注意到响应时间的增加。

这里是10个并发线程处理40个请求的报告

document Length:        613480 bytes

Concurrency Level:      10
Time taken for tests:   9.079 seconds
Complete requests:      40
Failed requests:        0
Write errors:           0
Total transferred:      24542960 bytes
HTML transferred:       24539200 bytes
Requests per second:    4.41 [#/sec] (mean)
Time per request:       2269.770 [ms] (mean)
Time per request:       226.977 [ms] (mean, across all concurrent requests)
Transfer rate:          2639.89 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.8      0       5
Processing:  1250 2111 300.0   2126    2880
Waiting:     1024 1917 307.9   1948    2840
Total:       1255 2111 299.6   2126    2880

Percentage of the requests served within a certain time (ms)
50%   2126
66%   2213
75%   2233
80%   2243
90%   2446
95%   2865
98%   2880
99%   2880
100%   2880 (longest request)

注意如果仅使用2个并发线程,响应时间会下降

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:   279  447 140.9    415    1033
Waiting:      224  397 140.1    405    1000
Total:        279  447 140.9    415    1033

Percentage of the requests served within a certain time (ms)
50%    415
66%    422
75%    430
80%    434
90%    463
95%   1007
98%   1033
99%   1033
100%   1033 (longest request)

当只有一个客户端时,它是超快的

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:   189  207  14.7    205     265
Waiting:      186  205  14.5    203     262
Total:        189  207  14.7    205     265

Percentage of the requests served within a certain time (ms)
50%    205
66%    209
75%    214
80%    217
90%    224
95%    240
98%    265
99%    265
100%    265 (longest request)

以下是在同一数据和同一台机器上运行的节点的输出

Document Length:        807396 bytes

Concurrency Level:      10
Time taken for tests:   3.955 seconds
Complete requests:      40
Failed requests:        0
Write errors:           0
Total transferred:      32304320 bytes
HTML transferred:       32295840 bytes
Requests per second:    10.11 [#/sec] (mean)
Time per request:       988.661 [ms] (mean)
Time per request:       98.866 [ms] (mean, across all concurrent requests)
Transfer rate:          7977.25 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.5      0       3
Processing:   954  987  18.6   1000    1007
Waiting:      116  567 272.1    598     999
Total:        954  987  18.7   1001    1007

Percentage of the requests served within a certain time (ms)
50%   1001
66%   1004
75%   1004
80%   1004
90%   1005
95%   1005
98%   1007
99%   1007
100%   1007 (longest request)

据我所知,如果我在事件队列上放了很多事件,响应时间会增加。但我预计飞镖会使用微型机器来更早地处理等待事件。

这里是数据样本,结果数组总是包含1000个项目

{
    "numFound": 1234,
    "results": [
        {
            "cid": "id",
            "cir": "id",
            "cn": "name",
            "cbr": "string",
            "crn": "string",
            "dep": "string",
            "depid": "id",
            "fn": "string",
            "jvid": "id",
            "loc": "string",
            "pid": "id",
            "date": int,
            "toe": "string",
            "ujn": "string",
            "vn": "string",
            "ind": "string",
            "indid": "id",
            "fun": "string",
            "funid": "id",
            "des": "string",
            "date2": int,
            "uuid": "string",
            "elv": "string",
            "elvid": "id",
            "cfv": Array<Objects>
        }
    ]
}

我正在使用centos 6.5(我已经建立了dart 1.2 sdk)。我用

运行应用程序
  

perf record -g - dart --generate_perf_events_symbols start.dart

这就是'perf report --call-graph flat'所示,但我不知道如何解释输出以改进我的代码。

    75.86%  dart  [kernel.kallsyms]    [k] __do_softirq
+   3.62%  dart  dart                 [.] dart::MarkingVisitor::VisitPointers(dart::RawObject**, dart::RawObject**)
+   1.36%  dart  dart                 [.] dart::ScavengerVisitor::VisitPointers(dart::RawObject**, dart::RawObject**)
+   1.02%  dart  dart                 [.] dart::GCSweeper::SweepPage(dart::HeapPage*, dart::FreeList*)
+   0.96%  dart  perf-5465.map        [.] *dart:core_StringBuffer_writeCharCode
+   0.74%  dart  perf-5465.map        [.] *dart:convert__Utf8Decoder@0xda80e0a_convert
+   0.71%  dart  perf-5465.map        [.] *dart:convert__JsonStringifier@0xda80e0a_escape
+   0.57%  dart  perf-5465.map        [.] *dart:convert__Utf8Encoder@0xda80e0a__fillBuffer@0xda80e0a
+   0.55%  dart  libc-2.12.so         [.] _wordcopy_fwd_aligned
    0.53%  dart  [kernel.kallsyms]    [k] retint_careful
+   0.52%  dart  perf-5465.map        [.] *dart:core_StringBuffer__addPart@0x36924d72
    0.50%  dart  [kernel.kallsyms]    [k] finish_task_switch
    0.49%  dart  dart                 [.] dart::RawObject::VisitPointers(dart::ObjectPointerVisitor*)
    0.41%  dart  [vsyscall]           [.] 0x000000000000014c
    0.38%  dart  libc-2.12.so         [.] memmove
    0.29%  dart  libpthread-2.12.so   [.] pthread_getspecific
    0.29%  dart  dart                 [.] dart::FreeList::TryAllocate(long, bool)
    0.28%  dart  perf-5465.map        [.] dart:core__List@0x36924d72__List@0x36924d72.
    0.28%  dart  perf-5465.map        [.] *dart:convert__JsonParser@0xda80e0a_parse
    0.27%  dart  perf-5465.map        [.] *dart:core_StringBuffer_write
    0.27%  dart  perf-5465.map        [.] *package:public-api/publicApi.dart_PostingResultMapper_mapPosting_mapPosting
    0.27%  dart  [kernel.kallsyms]    [k] _spin_unlock_irqrestore
    0.27%  dart  dart                 [.] dart::String::Copy(dart::String const&, long, unsigned char const*, long)
    0.27%  dart  dart                 [.] dart::VMHandles::AllocateHandle(dart::Isolate*)
    0.26%  dart  perf-5465.map        [.] *dart:collection__HashMap@0x23c35ea0&&_LinkedHashMapMixin@0x23c35ea0_forEach
    0.25%  dart  perf-5465.map        [.] *dart:convert__JsonStringifier@0xda80e0a_stringifyJsonValue
    0.24%  dart  dart                 [.] dart::Object::Allocate(long, long, dart::Heap::Space)
    0.24%  dart  perf-5465.map        [.] dart:core__StringBase@0x36924d72_codeUnitAt
    0.23%  dart  dart                 [.] dart::GCMarker::DrainMarkingStack(dart::Isolate*, dart::MarkingVisitor*)
    0.22%  dart  dart                 [.] dart::ClassTable::UpdateLiveOld(long, long)
    0.22%  dart  perf-5465.map        [.] *dart:convert__JsonParser@0xda80e0a_parseString
    0.21%  dart  perf-5465.map        [.] *dart:convert__JsonParser@0xda80e0a_parseString
    0.20%  dart  dart                 [.] dart::String::Copy(dart::String const&, long, dart::String const&, long, long)
    0.17%  dart  dart                 [.] dart::OneByteString::ConcatAll(dart::Array const&, long, long, long, dart::Heap::Space)
    0.16%  dart  [kernel.kallsyms]    [k] __do_page_fault
    0.16%  dart  dart                 [.] dart::BootstrapNatives::DN_StringBase_substringUnchecked(_Dart_NativeArguments*)
    0.15%  dart  dart                 [.] dart::String::ConcatAllRange(dart::Array const&, long, long, dart::Heap::Space)
    0.15%  dart  perf-5465.map        [.] *dart:core_StringBuffer__consumeBuffer@0x36924d72
    0.14%  dart  [kernel.kallsyms]    [k] clear_page_c
    0.13%  dart  perf-5465.map        [.] _stub_OneArgCheckInlineCache
    0.12%  dart  perf-5465.map        [.] *dart:core__StringBase@0x36924d72_substring
    0.11%  dart  dart                 [.] dart::String::Copy(dart::String const&, long, unsigned short const*, long)
    0.11%  dart  perf-5465.map        [.] *dart:collection__HashMap@0x23c35ea0&&_LinkedHashMapMixin@0x23c35ea0__addEntry@0x23c35ea0
    0.11%  dart  dart                 [.] dart::String::SubString(dart::String const&, long, long, dart::Heap::Space)
    0.11%  dart  dart                 [.] dart::FreeList::SplitElementAfterAndEnqueue(dart::FreeListElement*, long, bool)
    0.10%  dart  [kernel.kallsyms]    [k] get_page_from_freelist
    0.10%  dart  dart                 [.] 0x000000000031b333
    0.10%  dart  dart                 [.] dart::Scavenger::ProcessToSpace(dart::ScavengerVisitor*)
    0.09%  dart  dart                 [.] dart::RawArray::VisitArrayPointers(dart::RawArray*, dart::ObjectPointerVisitor*)
    0.09%  dart  dart                 [.] dart::ClassTable::UpdateAllocatedOld(long, long)
    0.08%  dart  dart                 [.] dart::Profiler::RecordSampleInterruptCallback(dart::InterruptedThreadState const&, void*)
    0.08%  dart  dart                 [.] dart::BootstrapNatives::DN_String_concatRange(_Dart_NativeArguments*)
    0.08%  dart  perf-5465.map        [.] *dart:convert__JsonStringifier@0xda80e0a_stringifyJsonValue_<anonymous closure>
    0.07%  dart  perf-5465.map        [.] _stub_TwoArgsCheckInlineCache
    0.07%  dart  dart                 [.] dart::BootstrapNatives::DN_Object_getHash(_Dart_NativeArguments*)
    0.07%  dart  perf-5465.map        [.] *dart:core__Smi@0x36924d72_toString
    0.07%  dart  perf-5465.map        [.] dart:core__OneByteString@0x36924d72_get_hashCode
    0.07%  dart  dart                 [.] dart::Instance::IsInstance() const
    0.06%  dart  dart                 [.] dart::BootstrapNatives::DN_StringBuffer_createStringFromUint16Array(_Dart_NativeArguments*)
    0.06%  dart  perf-5465.map        [.] *dart:collection_Maps_mapToString
    0.06%  dart  dart                 [.] dart::VMHandles::~VMHandles()
    0.06%  dart  dart                 [.] dart::GCMarker::MarkObjects(dart::Isolate*, dart::PageSpace*, bool, bool)
    0.06%  dart  dart                 [.] dart::PageSpace::TryAllocate(long, dart::HeapPage::PageType, dart::PageSpace::GrowthPolicy)
    0.06%  dart  [kernel.kallsyms]    [k] free_hot_cold_page
    0.06%  dart  perf-5465.map        [.] dart:core__StringBase@0x36924d72__substringUncheckedNative@0x36924d72
    0.06%  dart  dart                 [.] dart::LoadOptimizer::Optimize()
    0.06%  dart  dart                 [.] dart::Heap::AllocateNew(long)

1 个答案:

答案 0 :(得分:1)

我只想总结一下我发现的有关dm在vm上的行为。在直接询问后发现变换是一个严重的问题。

这已经在最新版本中得到了改进,并且也应该包含在下一个稳定版本中。

请检查此错误https://code.google.com/p/dart/issues/detail?id=17659以及来自drt google论坛的对话本身https://groups.google.com/a/dartlang.org/forum/#!topic/misc/S0rGeyc9aQU

非常感谢Gunter,Anders和Greg在这里帮助我。