-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:(ast) Node
support concurrently-read
#661
Conversation
Node
support concurrently-read
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #661 +/- ##
==========================================
- Coverage 52.85% 51.81% -1.05%
==========================================
Files 174 128 -46
Lines 11470 10844 -626
==========================================
- Hits 6063 5619 -444
+ Misses 5071 4906 -165
+ Partials 336 319 -17 ☔ View full report in Codecov by Sentry. |
4d7daf3
to
95e7de9
Compare
一个全局的问题,我们是否需要同时维护 lazy 和 loadonce 两种状态,按理说一个node的状态只有三种:1. all loaded, 2, lazied, 3, loadonce with lock ? 如果parser 里面同时有noLazy 和loadonce 两个属性的话,会增加不必要的复杂度 |
lazyload还是有其存在的价值,不是所有业务都有并发加载的需求 |
Background
Since sonic uses
Lazy-Load
design to parse JSON nodes on demands, it doesn't supportconcurrently-Read
by default. But in practice, we found many users may use it in such scenarios and cause panic.Desgin
Thus we design one kind of
State Transition Lock
to achieve the goal by least cost. In brief:Lazy
state (parse transversely on demands). Every node has only two state:Parsed
(bool, number, or object slice...) orRaw
(JSON), and the only transit direction isRaw->Parsed
;Get()
) will check its state usingAtomic Load
:Write Lock
Raw()
andMarshalJSON()
). In these circumstances, we need keep the Raw state to achieve the best performance. Thus useRead Lock
to keep the state.Performance
Load/LoadAll will be faster a lot
Load/LoadAll()
will automatically add lock for Node, instead of parsing all children nodes. This will help to benefits users who use them for supporting concurrently-readGet() will be slower on small data but faster on large data
Node.Get()
will generally fasterGet()
will useatomic
operation to check state, it will be a bit slowerBenchmark