Skip to content
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

small experiment with cJSON #833

Closed
wants to merge 6 commits into from
Closed

Conversation

garlick
Copy link
Member

@garlick garlick commented Oct 5, 2016

The cJSON library is small, embeddable, reasonably fast (see JSON benchmarks), and seems widely used. It implements "JSON patch", as described in RFC 6902 which may have applications in the KVS, perhaps as a replacement for the ad-hoc "operation" array in the commit request. I'm curious whether switching to cJSON might not be a useful idea in the KVS internally, particularly if "JSON patch" can be used there. I'm also wondering if this API might be a little nicer than json-c.

In this PR, I embedded the library in flux-core and converted flux-kvs to use it as an experiment. So far, well...not too bad I guess. A couple of interesting bits relative to json-c:

  • It allows malloc/free functions to be registered by the user
  • it is not refcounted (I'm not sure if that as good or bad at this point!)
  • it only implements the "number" type, not int, int64, and double like json-c.
  • no name collisions with json-c (unlike jansson) so it doesn't require all or nothing investment

Some problems noted so far

  • code is nearly unreadable (e.g. needs to be reformatted IMHO)
  • malloc/free pointers are stored in globals which might not work for broker/modules (move to TLS?)
  • if you don't register a "fatal" malloc/free, checking for ENOMEM is a bit tricky (e.g. checking for NULL structure members - requires peeking at source)

Not for merging - just a checkpoint.

@garlick garlick added the review label Oct 5, 2016
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.004%) to 75.341% when pulling 55ec91a on garlick:cjson into dc58fcb on flux-framework:master.

@grondo
Copy link
Contributor

grondo commented Oct 5, 2016

Wow, cJSON kind of feels like the result of late night bet to get a C JSON library under 800 lines. However, it does seem like it is actually used by other projects.

Maybe we could start with cJSON and make something reasonably safe and fast ourselves that implements JSON patch?

@garlick
Copy link
Member Author

garlick commented Oct 5, 2016

Yeah starting with running it through indent!

@codecov-io
Copy link

codecov-io commented Oct 5, 2016

Current coverage is 73.17% (diff: 5.40%)

Merging #833 into master will decrease coverage by 1.86%

@@             master       #833   diff @@
==========================================
  Files           146        148     +2   
  Lines         25415      26097   +682   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          19071      19096    +25   
- Misses         6344       7001   +657   
  Partials          0          0          
Diff Coverage File Path
0% new src/common/libcjson/cJSON.c
0% new src/common/libcjson/cJSON_Utils.c
•••••• 67% src/cmd/flux-kvs.c

Powered by Codecov. Last update dc58fcb...4882ec1

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 75.303% when pulling f1d06e6 on garlick:cjson into dc58fcb on flux-framework:master.

Tweak the supplied unit test so that it emits TAP output
and checks its own success/failure.
Use cJSON library instead of shortjson/json-c.

Give cJSON fatal malloc/free functions so some repetitive error
checking can be avoided.

Use the base64 codec directly rather than through the
base64_json.c convenience functions, since those assume json-c.

Retain old behavior of printing strings unquoted and objects
with compact formatting.  Slight changes in array and object output
result from different cJSON defaults.
Adjust spacing in expected array and object output.

"int" and "double" are no longer distinct types.  Instead,
the "number" type encompasses both.  The JSON spec (RFC 7159)
in fact only defines the number type.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.004%) to 75.341% when pulling 4882ec1 on garlick:cjson into dc58fcb on flux-framework:master.

@garlick
Copy link
Member Author

garlick commented Oct 5, 2016

Looks like code reformatting is in the queue upstream, see DaveGamble/cJSON#24

@grondo
Copy link
Contributor

grondo commented Oct 5, 2016

Just remembered that @trws had checked in rules for clang-format that follow our style guide if indent doesn't give you great results. Try uncommenting the clang-3.7 lines in .clang-format if you have a recent version.

@lipari
Copy link
Contributor

lipari commented Oct 5, 2016

We have RFC 7 that provides guidance on how to make our code look uniformly pretty. I would suggest we add to it whatever tools or options that best do the job.

@garlick
Copy link
Member Author

garlick commented Oct 5, 2016

Thanks guys, I'll probably just wait for the reformatting to come from upstream since it's any day now, and then we'll be able to stay in sync and not subvert automatic rebase of any patches we carry. Assuming this experiment withstands the light of day that is!

@garlick
Copy link
Member Author

garlick commented Oct 5, 2016

For the record, In #301 we discussed replacing json-c at length. For C, it sounded like jansson was the preferred option, but since there are some functions in json-c and jansson that have the same name, we ran into troubles transitioning. As I understand it, libflux had been migrated to jansson in #319, while other parts of flux-core like the kvs module still used json-c. The json-c users would pick up libflux's dependencies when built in-tree via the libtool scripts and get one of the duplicate symbols from the wrong lib.

It was thought that pulling json-c in and building it statically as part of libflux-internal would address this, but for some reason I didn't press ahead and just do that to get us through the transition.

@garlick garlick mentioned this pull request Oct 7, 2016
@DaveGamble
Copy link

@grondo You are unbelievably close to the truth with your guess as to the origins of cJSON. ;)
If you'd guessed mid-afternoon rather than late-night, you'd have gotten full marks! :D

@grondo
Copy link
Contributor

grondo commented Oct 9, 2016

@DaveGamble, well then kudos are in order! nice job on cJSON, and thanks for the software!

@grondo
Copy link
Contributor

grondo commented Oct 14, 2016

Is this PR dead, Jim?

@garlick
Copy link
Member Author

garlick commented Oct 14, 2016

You mean...
star-trek-hes-dead-jim
Not quite.

@garlick
Copy link
Member Author

garlick commented Oct 19, 2016

Think I'll withdraw this for now - still on the back burner.

@garlick garlick closed this Oct 19, 2016
@garlick garlick removed the review label Oct 19, 2016
@garlick garlick deleted the cjson branch September 6, 2017 15:53
grondo added a commit to grondo/flux-core that referenced this pull request Feb 5, 2019
The wreck exec system is worthless, remove it along with associated
commands, tests, and support code.

Since libjsc doesn't work without wreck, it is removed as well.

Fixes flux-framework#1984
Closes flux-framework#1947
Closes flux-framework#1618
Closes flux-framework#1595
Closes flux-framework#1593
Closes flux-framework#1468
Closes flux-framework#1438
Closes flux-framework#1419
Closes flux-framework#1410
Closes flux-framework#915
Closes flux-framework#894
Closes flux-framework#866
Closes flux-framework#833
Closes flux-framework#774
Closes flux-framework#772
Closes flux-framework#335
Closes flux-framework#249
grondo added a commit to grondo/flux-core that referenced this pull request Feb 5, 2019
The wreck exec system is worthless, remove it along with associated
commands, tests, and support code.

Since libjsc doesn't work without wreck, it is removed as well.

Fixes flux-framework#1984

Closes flux-framework#1947
Closes flux-framework#1618
Closes flux-framework#1595
Closes flux-framework#1593
Closes flux-framework#1534
Closes flux-framework#1468
Closes flux-framework#1443
Closes flux-framework#1438
Closes flux-framework#1419
Closes flux-framework#1410
Closes flux-framework#1407
Closes flux-framework#1393
Closes flux-framework#915
Closes flux-framework#894
Closes flux-framework#866
Closes flux-framework#833
Closes flux-framework#774
Closes flux-framework#772
Closes flux-framework#335
Closes flux-framework#249
grondo added a commit to grondo/flux-core that referenced this pull request Feb 5, 2019
The wreck exec system is worthless, remove it along with associated
commands, tests, and support code.

Since libjsc doesn't work without wreck, it is removed as well.

Fixes flux-framework#1984

Closes flux-framework#1947
Closes flux-framework#1618
Closes flux-framework#1595
Closes flux-framework#1593
Closes flux-framework#1534
Closes flux-framework#1468
Closes flux-framework#1443
Closes flux-framework#1438
Closes flux-framework#1419
Closes flux-framework#1410
Closes flux-framework#1407
Closes flux-framework#1393
Closes flux-framework#915
Closes flux-framework#894
Closes flux-framework#866
Closes flux-framework#833
Closes flux-framework#774
Closes flux-framework#772
Closes flux-framework#335
Closes flux-framework#249
grondo added a commit to grondo/flux-core that referenced this pull request Feb 9, 2019
The wreck exec system is worthless, remove it along with associated
commands, tests, and support code.

Since libjsc doesn't work without wreck, it is removed as well.

Fixes flux-framework#1984

Closes flux-framework#1947
Closes flux-framework#1618
Closes flux-framework#1595
Closes flux-framework#1593
Closes flux-framework#1534
Closes flux-framework#1468
Closes flux-framework#1443
Closes flux-framework#1438
Closes flux-framework#1419
Closes flux-framework#1410
Closes flux-framework#1407
Closes flux-framework#1393
Closes flux-framework#915
Closes flux-framework#894
Closes flux-framework#866
Closes flux-framework#833
Closes flux-framework#774
Closes flux-framework#772
Closes flux-framework#335
Closes flux-framework#249
@grondo
Copy link
Contributor

grondo commented Feb 13, 2019

closed by #1988

chu11 pushed a commit to chu11/flux-core that referenced this pull request Feb 13, 2019
The wreck exec system is worthless, remove it along with associated
commands, tests, and support code.

Since libjsc doesn't work without wreck, it is removed as well.

Fixes flux-framework#1984
Closes flux-framework#1947
Closes flux-framework#1618
Closes flux-framework#1595
Closes flux-framework#1593
Closes flux-framework#1468
Closes flux-framework#1438
Closes flux-framework#1419
Closes flux-framework#1410
Closes flux-framework#915
Closes flux-framework#894
Closes flux-framework#866
Closes flux-framework#833
Closes flux-framework#774
Closes flux-framework#772
Closes flux-framework#335
Closes flux-framework#249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants