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

Improve Registration.getSortedObjectLinks performance #504

Closed
lhotari opened this issue May 15, 2018 · 3 comments
Closed

Improve Registration.getSortedObjectLinks performance #504

lhotari opened this issue May 15, 2018 · 3 comments
Labels
demo Impact our demo (not libraries) new feature New feature from LWM2M specification server Impact LWM2M server

Comments

@lhotari
Copy link

lhotari commented May 15, 2018

Leshan 1.0.0-M9

Current behaviour:
When using the Leshan Demo server, there are a lot of this type of exceptions when there are a lot of registrations:

java.lang.NumberFormatException.<init>(String)
at java.lang.NumberFormatException.forInputString(String)
at java.lang.Integer.parseInt(String, int)
at java.lang.Integer.parseInt(String)
at org.eclipse.leshan.server.registration.Registration.isNumber(String)
at org.eclipse.leshan.server.registration.Registration.access$000(String)
at org.eclipse.leshan.server.registration.Registration$1.compare(Link, Link)
at org.eclipse.leshan.server.registration.Registration$1.compare(Object, Object)
at java.util.TimSort.countRunAndMakeAscending(Object[], int, int, Comparator)
at java.util.TimSort.sort(Object[], int, int, Comparator, Object[], int, int)
at java.util.Arrays.sort(Object[], Comparator)
at org.eclipse.leshan.server.registration.Registration.getSortedObjectLinks()
at org.eclipse.leshan.server.demo.servlet.json.RegistrationSerializer.serialize(Registration, Type, JsonSerializationContext)
at org.eclipse.leshan.server.demo.servlet.json.RegistrationSerializer.serialize(Object, Type, JsonSerializationContext)

originating from https://github.com/eclipse/leshan/blob/e438d749ba997abb63ed49504ada17cde1240c1e/leshan-server-demo/src/main/java/org/eclipse/leshan/server/demo/servlet/EventServlet.java#L85

Expected behaviour:
Normal operations shouldn't create a large number of exceptions. It seems that Registration.isNumber could be improved so that it doesn't throw exceptions. A good example for a better approach is the one in Commons Lang StringUtils.isNumeric

sbernard31 added a commit that referenced this issue May 23, 2018
@sbernard31
Copy link
Contributor

Demo is just a demo. We don't aim to handle a lot of registrations.

Anyway, the fix proposed sounds good.

I made some bench ...

Benchmark                         Mode  Cnt         Score         Error  Units
IsNumericTest.testIsNumber       thrpt    3  26590429,681 ± 2885084,088  ops/s
IsNumericTest.testIsNumberFail   thrpt    3  26459725,741 ±  412815,205  ops/s
IsNumericTest.testIsNumeric      thrpt    3  41837663,625 ±  490409,437  ops/s
IsNumericTest.testIsNumericFail  thrpt    3  41675654,458 ±  663382,727  ops/s

... and write a PR about that : #506
Could you confirm this behave better ?

@sbernard31 sbernard31 added new feature New feature from LWM2M specification server Impact LWM2M server demo Impact our demo (not libraries) labels May 23, 2018
@lhotari
Copy link
Author

lhotari commented May 23, 2018

LGTM , thank you @sbernard31

@sbernard31
Copy link
Contributor

Integrated in master. (commit e57c417)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
demo Impact our demo (not libraries) new feature New feature from LWM2M specification server Impact LWM2M server
Projects
None yet
Development

No branches or pull requests

2 participants