Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:31:32+00:00 2026-05-26T23:31:32+00:00

To resolve this issue I have created an open source Java Thread Affinity library

  • 0

To resolve this issue I have created an open source Java Thread Affinity library

When I have a number of thread interacting closely it can reduce latency and increase throughput. For single threaded tasks it can still reduce jitter quite a bit.


This program looks at the difference in time between calls to System.nanoTime() and reports those over 10x,000 ns.

public class TimeJumpingMain {
    static final long IGNORE_TIME = 1000 * 1000 * 1000; // the first second to allow warmup.
    static final int minJump = 10; // smallest jump of 10 us.
    static final int midJump = 100; // mid size jump of 100 us.
    static final int bigJump = 1000; // big jump of 1 ms.

    public static void main(String... args) {
        int[] intervalTimings = new int[1000];
        int[] jumpTimings = new int[1000];

        long start = System.nanoTime();
        long prev = start;
        long prevJump = start;
        int jumpCount = 0;
        int midJumpCount = 0;
        int bigJumpCount = 0;

        while (true) {
            long now = System.nanoTime();
            long jump = (now - prev) / 1000;
            if (jump > minJump && now - start > IGNORE_TIME) {
                long interval = (now - prevJump) / 1000;
                if (jumpCount < intervalTimings.length) {
                    intervalTimings[jumpCount] = (int) interval;
                    jumpTimings[jumpCount] = (int) jump;
                }
                if (jump >= midJump)
                    midJumpCount++;
                if (jump >= bigJump)
                    bigJumpCount++;
                prevJump = now;
                jumpCount++;
            }
            prev = now;
            if (now - start > 120L * 1000 * 1000 * 1000 + IGNORE_TIME)
                break;
        }
        System.out.println("interval us\tdelay us");
        for (int i = 0; i < jumpCount && i < intervalTimings.length; i++) {
            System.out.println(intervalTimings[i] + "\t" + jumpTimings[i]);
        }
        System.out.printf("Time jumped %,d / %,d / %,d times by at least %,d / %,d / %,d us in %.1f seconds %n",
                jumpCount, midJumpCount, bigJumpCount, minJump, midJump, bigJump, (System.nanoTime() - start - IGNORE_TIME) / 1e9);
    }
}

on my machine this reports

Time jumped 2,905 / 131 / 20 times by at least 10 / 100 / 1,000 us in 120.0 seconds   

I have tried chrt to set real time priority and taskset to try to lock to a single core AFTER STARTING the process but these didn’t help as I expected.

I configured the box to move all interrupts to cpus 0-3 and the cpu mask for all process with 0xFF to 0x0F. In top the first four cpus are ~99% idle and the last four cpus are 100.0% idle.

Using chrt -r 99 as root

Time jumped 673 / 378 / 44 times by at least 10 / 100 / 1,000 us in 120.0 seconds 

However, when using taskset -c 7 alone (I have made sure cpu7 is free)

Time jumped 24 / 1 / 0 times by at least 10 / 100 / 1,000 us in 120.0 seconds 

Using chrt - r 99 taskset -c 7

Time jumped 7 / 1 / 0 times by at least 10 / 100 / 1,000 us in 120.0 seconds  

It appears that trying to use taskset after the process had started wasn’t working for me.

The broader question is;

How to reduce jitter for a Java process? Are there any more tips for reducing jitter on Linux?

NOTE: No GC occurs during the running of this process (checked with -verbosegc)

It appears that code compiling may cause a delay of 3.62 ms every time after 100 – 102 ms. For this reason I ignore everything in the first second as warmup.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:31:33+00:00Added an answer on May 26, 2026 at 11:31 pm

    There’s system jitter and JVM jitter.

    For the former you can use the isolcpus parameter at boot time to ensure that nothing but your application code can run on those cpus

    http://www.novell.com/support/viewContent.do?externalId=7009596&sliceId=1

    Ideally you’d do a jni call (to your own jni lib) down to sched_setaffinity just for the active thread so that you really do have nothing but that thread running there.

    In my experience, system jitter is minimised by use of isolcpus with interrupts handled by specific cores only, hyper threading switched off and absolutely all use of power management removed (these are bios options when they’re available to turn off all the c-state & p-state management) while running your app on shielded cores. The bios specific options are obviously specific to your motherboard so you’ll need to look into that based on your motherboard model.

    Another thing look at at the system level is the local APIC interrupt (LOC, local interrupt counter) frequency. Is this a “low latency desktop” using 1kHz interrupts? either way, you can expect jitter to be clustered around the interrupt interval

    2 more I know practically nothing about but am aware of as sources of jitter; kernel tlb flush interrupts and userspace tlb flush interrupts. Some RT kernels offer options to control these so this might be another thing to look into. You can also look at this site about building RT apps on the RT kernel for more tips.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I've spent a couple hours trying to resolve this issue and have
I can't resolve this issue, I found a similar question here but: setting the
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Up to this moment, I still have no luck to resolve this Chinese characters
We have a Java Applet built using AWT. This applet lets you select pictures
Update: This issue has been resolved. you can read about the solution in here:
I resolved this issue myself. It turns out that the activation framework requires some
**c:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(0,0): warning MSB3245: Could not resolve this reference. Could not locate the assembly System.Web.Mvc,
Well, maybe it is a stupid question, but I cannot resolve this problem. In
if(strpos(http://www.example.com,http://www.)==0){ // do work} I'd expect this to resolve as true, which it does.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.