palantir / atlasdb

Transactional Distributed Database Layer
https://palantir.github.io/atlasdb/
Apache License 2.0
44 stars 7 forks source link

Timelock uses tritium-preprocessor instrumentation #7132

Closed schlosna closed 1 week ago

schlosna commented 1 month ago

General

Before this PR:

Timelock triggered some blocked thread monitors indicating there is still some contention even after https://github.com/palantir/atlasdb/pull/7117 .

The class loading contention bits are interesting as those are part of what is causing the blocking in ConcurrentHashMap#computeIfAbsent when creating a new timelock namespace client com.palantir.atlasdb.timelock.TimelockNamespaces.createNewClient(String):137 as that instruments the AsyncTimelockService and LockService instances.

We can optimize some of this using tritium's annotation processor compile time generated instrumentation (see also https://github.com/palantir/tritium/pull/1083 )

java.util.zip.ZipFile.getEntry(String):337
   java.util.jar.JarFile.getEntry(String):516
   sun.net.www.protocol.jar.URLJarFile.getEntry(String):128
   sun.net.www.protocol.jar.JarURLConnection.connect():113
   sun.net.www.protocol.jar.JarURLConnection.getInputStream():153
   java.net.URL.openStream():1325
   java.lang.ClassLoader.getResourceAsStream(String):1764
   net.bytebuddy.dynamic.ClassFileLocator$ForClassLoader.locate(ClassLoader, String):454
   net.bytebuddy.dynamic.ClassFileLocator$ForClassLoader.locate(String):435
   net.bytebuddy.asm.Advice.to(TypeDescription, Advice$PostProcessor$Factory, ClassFileLocator, List, Advice$Delegator$Factory):406
   net.bytebuddy.asm.Advice$WithCustomMapping.to(TypeDescription, ClassFileLocator):15438
   net.bytebuddy.asm.Advice$WithCustomMapping.to(Class, ClassFileLocator):15427
   net.bytebuddy.asm.Advice$WithCustomMapping.to(Class):15416
   com.palantir.tritium.proxy.ByteBuddyInstrumentation.lambda$newInstrumentationClass$0(ImmutableList, Class, ClassLoader):163
   com.palantir.tritium.proxy.ByteBuddyInstrumentation$$Lambda+0x0000000080794b20.1795075885.call():-1
   net.bytebuddy.TypeCache.findOrInsert(ClassLoader, Object, Callable):168
   net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(ClassLoader, Object, Callable):399
   com.palantir.tritium.proxy.ByteBuddyInstrumentation.newInstrumentationClass(ClassLoader, Class, ImmutableList):133
   com.palantir.tritium.proxy.ByteBuddyInstrumentation.instrument(Class, Object, List, InstrumentationFilter):103
   com.palantir.tritium.proxy.Instrumentation.wrap(Class, Object, List, InstrumentationFilter):64
   com.palantir.tritium.proxy.Instrumentation$Builder.build():207
   com.palantir.atlasdb.util.AtlasDbMetrics.instrumentWithTaggedMetrics(TaggedMetricRegistry, Class, Object, Function):91
   com.palantir.atlasdb.timelock.paxos.TimelockLeadershipMetrics.instrument(Class, Object):63
   com.palantir.atlasdb.timelock.paxos.LeadershipComponents.wrapInLeadershipProxy(Client, Class, Supplier):65
   com.palantir.timelock.paxos.AsyncTimeLockServicesCreator.createTimeLockServices(Client, Supplier, Supplier):72
      com.palantir.timelock.paxos.TimeLockAgent.createInvalidatingTimeLockServices(String):598
      com.palantir.timelock.paxos.TimeLockAgent$$Lambda+0x0000000080900220.390560699.apply(Object):-1
      com.palantir.atlasdb.timelock.TimelockNamespaces.createNewClient(String):137
      com.palantir.atlasdb.timelock.TimelockNamespaces.lambda$get$0(String, Optional, String):103
      com.palantir.atlasdb.timelock.TimelockNamespaces$$Lambda+0x0000000080a87c08.2121677684.apply(Object):-1
      java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Object, Function):1708
      com.palantir.atlasdb.timelock.TimelockNamespaces.get(String, Optional):98

image

After this PR:

==COMMIT_MSG== Timelock uses tritium-preprocessor instrumentation ==COMMIT_MSG==

Priority:

Concerns / possible downsides (what feedback would you like?):

Is documentation needed?:

Compatibility

Does this PR create any API breaks (e.g. at the Java or HTTP layers) - if so, do we have compatibility?:

Does this PR change the persisted format of any data - if so, do we have forward and backward compatibility?:

The code in this PR may be part of a blue-green deploy. Can upgrades from previous versions safely coexist? (Consider restarts of blue or green nodes.):

Does this PR rely on statements being true about other products at a deployment - if so, do we have correct product dependencies on these products (or other ways of verifying that these statements are true)?:

Does this PR need a schema migration?

Testing and Correctness

What, if any, assumptions are made about the current state of the world? If they change over time, how will we find out?:

What was existing testing like? What have you done to improve it?:

If this PR contains complex concurrent or asynchronous code, is it correct? The onus is on the PR writer to demonstrate this.:

If this PR involves acquiring locks or other shared resources, how do we ensure that these are always released?:

Execution

How would I tell this PR works in production? (Metrics, logs, etc.):

Has the safety of all log arguments been decided correctly?:

Will this change significantly affect our spending on metrics or logs?:

How would I tell that this PR does not work in production? (monitors, etc.):

If this PR does not work as expected, how do I fix that state? Would rollback be straightforward?:

If the above plan is more complex than “recall and rollback”, please tag the support PoC here (if it is the end of the week, tag both the current and next PoC):

Scale

Would this PR be expected to pose a risk at scale? Think of the shopping product at our largest stack.:

Would this PR be expected to perform a large number of database calls, and/or expensive database calls (e.g., row range scans, concurrent CAS)?:

Would this PR ever, with time and scale, become the wrong thing to do - and if so, how would we know that we need to do something differently?:

Development Process

Where should we start reviewing?:

If this PR is in excess of 500 lines excluding versions lock-files, why does it not make sense to split it?:

Please tag any other people who should be aware of this PR: @jeremyk-91 @sverma30 @raiju

changelog-app[bot] commented 1 month ago

Generate changelog in changelog-dir>`changelog/@unreleased`</changelog-dir

What do the change types mean? - `feature`: A new feature of the service. - `improvement`: An incremental improvement in the functionality or operation of the service. - `fix`: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way. - `break`: Has the potential to break consumers of this service's API, inclusive of both Palantir services and external consumers of the service's API (e.g. customer-written software or integrations). - `deprecation`: Advertises the intention to remove service functionality without any change to the operation of the service itself. - `manualTask`: Requires the possibility of manual intervention (running a script, eyeballing configuration, performing database surgery, ...) at the time of upgrade for it to succeed. - `migration`: A fully automatic upgrade migration task with no engineer input required. _Note: only one type should be chosen._
How are new versions calculated? - ❗The `break` and `manual task` changelog types will result in a major release! - 🐛 The `fix` changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease. - ✨ All others will result in a minor version release.

Type

- [ ] Feature - [x] Improvement - [ ] Fix - [ ] Break - [ ] Deprecation - [ ] Manual task - [ ] Migration

Description

Timelock uses tritium-preprocessor instrumentation **Check the box to generate changelog(s)** - [x] Generate changelog entry
svc-autorelease commented 1 week ago

Failed to push a commit onto develop to move @unreleased changelogs

com.palantir.conjure.java.api.errors.UnknownRemoteException: Response status: 502
    at com.palantir.conjure.java.dialogue.serde.ErrorDecoder.decodeInternal(ErrorDecoder.java:123)
    at com.palantir.conjure.java.dialogue.serde.ErrorDecoder.decode(ErrorDecoder.java:68)
    at com.palantir.conjure.java.dialogue.serde.ConjureBodySerDe$EmptyBodyDeserializer.deserialize(ConjureBodySerDe.java:351)
    at com.palantir.conjure.java.dialogue.serde.ConjureBodySerDe$EmptyBodyDeserializer.deserialize(ConjureBodySerDe.java:338)
    at com.palantir.conjure.java.client.jaxrs.DialogueFeignClient$RemoteExceptionDecoder.decode(DialogueFeignClient.java:336)
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:134)
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
    at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
    at jdk.proxy2/jdk.proxy2.$Proxy83.createTree(Unknown Source)
    at jdk.internal.reflect.GeneratedMethodAccessor213.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.palantir.github.clients.PerTraceRequestCountingClientFactory.invoke(PerTraceRequestCountingClientFactory.java:35)
    at com.palantir.github.clients.PerTraceRequestCountingClientFactory.lambda$client$0(PerTraceRequestCountingClientFactory.java:29)
    at jdk.proxy2/jdk.proxy2.$Proxy83.createTree(Unknown Source)
    at jdk.internal.reflect.GeneratedMethodAccessor213.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.palantir.github.clients.ErrorTrackingExternalClientFactory.invoke(ErrorTrackingExternalClientFactory.java:36)
    at com.palantir.github.clients.ErrorTrackingExternalClientFactory.lambda$client$0(ErrorTrackingExternalClientFactory.java:30)
    at jdk.proxy2/jdk.proxy2.$Proxy83.createTree(Unknown Source)
    at com.palantir.autorelease.CommitFactory.createCommit(CommitFactory.java:100)
    at com.palantir.autorelease.CommitFactory.createCommit(CommitFactory.java:70)
    at com.palantir.autorelease.ReleaserHelper.moveChangelogs(ReleaserHelper.java:64)
    at com.palantir.autorelease.Releaser.labelRelease(Releaser.java:229)
    at com.palantir.autorelease.DefaultRepositoryArchetype.automatedRelease(DefaultRepositoryArchetype.java:117)
    at com.palantir.autorelease.Repository.automatedRelease(Repository.java:63)
    at com.palantir.autorelease.label.DefaultWebhookHandler.handlePullRequestClosedEvent(DefaultWebhookHandler.java:224)
    at com.palantir.autorelease.label.DefaultWebhookHandler.handleWebhook(DefaultWebhookHandler.java:128)
    at com.palantir.github.GithubWebhookResource.lambda$receiveWebhook$0(GithubWebhookResource.java:58)
    at com.palantir.tracing.Tracers$TracingAwareRunnable.run(Tracers.java:584)
    at com.palantir.tritium.metrics.TaggedMetricsExecutorService$TaggedMetricsRunnable.run(TaggedMetricsExecutorService.java:142)
    at com.palantir.nylon.threads.RenamingExecutorService$RenamingRunnable.run(RenamingExecutorService.java:92)
    at org.jboss.threads.EnhancedViewExecutor$EnhancedViewExecutorRunnable.run(EnhancedViewExecutor.java:519)
    at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
    at com.palantir.tritium.metrics.TaggedMetricsThreadFactory$InstrumentedTask.run(TaggedMetricsThreadFactory.java:69)
    at java.base/java.lang.Thread.run(Thread.java:840)
    Suppressed: com.palantir.conjure.java.dialogue.serde.ErrorDecoder$ResponseDiagnostic: Response Diagnostic Information: {status=502, Server=GitHub.com, Content-Type=application/json, Content-Length=32, Date=Mon, 24 Jun 2024 20:49:49 GMT}
    Suppressed: com.palantir.logsafe.exceptions.SafeRuntimeException: unknown error: {serviceName=github, errorBody={
  "message": "Server Error"
}
}
        at com.palantir.github.clients.ErrorLoggingErrorTracker.trackUnknownRemoteError(ErrorLoggingErrorTracker.java:23)
        at com.palantir.github.clients.ErrorTracker.lambda$andAlso$0(ErrorTracker.java:14)
        at com.palantir.github.clients.ErrorTrackingExternalClientFactory.invoke(ErrorTrackingExternalClientFactory.java:41)
        ... 20 more