OpenHFT / Java-Thread-Affinity

Bind a java thread to a given core
http://chronicle.software/products/thread-affinity/
Apache License 2.0
1.78k stars 360 forks source link

Tried to set affinity to {3} but was {0, 1, 2, 3} you may have in sufficient access rights #99

Closed acuna-public closed 7 months ago

acuna-public commented 1 year ago

Trying it in Windows 7 (but I don't think it depends) on i5-4430 giving me this warnings:

[bg] INFO net.openhft.affinity.AffinityLock - Assigning cpu 3 to Thread[bg,5,main] on thread id 2548 [bg] WARN net.openhft.affinity.impl.WindowsJNAAffinity - Tried to set affinity to {3} but was {0, 1, 2, 3} you may have in sufficient access rights [bg-2] WARN net.openhft.affinity.LockInventory - Unable to acquire lock on CPU 3 for thread Thread[bg-2,5,main], trying to find another CPU [bg] INFO net.openhft.affinity.AffinityLock - Assigning cpu 1 to Thread[bg,5,main] on thread id 2548 [bg-2] INFO net.openhft.affinity.AffinityLock - Assigning cpu 2 to Thread[bg-2,5,main] on thread id 6512 [bg] WARN net.openhft.affinity.impl.WindowsJNAAffinity - Tried to set affinity to {1} but was {0, 1, 2, 3} you may have in sufficient access rights [bg-2] WARN net.openhft.affinity.impl.WindowsJNAAffinity - Tried to set affinity to {2} but was {0, 1, 2, 3} you may have in sufficient access rights [bg-2] WARN net.openhft.affinity.LockInventory - No reservable CPU for Thread[bg-2,5,main] [bg-3] WARN net.openhft.affinity.LockInventory - Unable to acquire lock on CPU 2 for thread Thread[bg-3,5,main], trying to find another CPU [bg-3] WARN net.openhft.affinity.LockInventory - No reservable CPU for Thread[bg-3,5,main] [bg-4] WARN net.openhft.affinity.LockInventory - Unable to acquire lock on CPU 2 for thread Thread[bg-4,5,main], trying to find another CPU [bg-4] WARN net.openhft.affinity.LockInventory - No reservable CPU for Thread[bg-4,5,main] [bg-4] WARN net.openhft.affinity.LockInventory - No reservable CPU for Thread[bg-4,5,main] [bg-3] WARN net.openhft.affinity.LockInventory - No reservable CPU for Thread[bg-3,5,main]

My pool is trivial:

ExecutorService pool = Executors.newFixedThreadPool (Runtime.getRuntime ().availableProcessors (), new AffinityThreadFactory ("bg", AffinityStrategies.ANY));

for (int i = 0; i < Runtime.getRuntime ().availableProcessors (); i++)
    pool.submit (new MyTask (this));

My task is trivial:

protected static class MyTask implements Runnable {

    @Override
    public void run () {

        AffinityLock al = AffinityLock.acquireLock ();

        try {

            // task

        } finally {
            al.close ();
        }

    }

}       

I'm using Gradle to build it:

implementation 'net.openhft:affinity:3.23.2'

Thanks in advance!

peter-lawrey commented 1 year ago

We haven't found a benefit on Windows as we have on Linux with isolated CPUs, so it is probably better to disable this for now.

huguera10 commented 1 year ago

I'm currently having the same issue, @acuna-public. Did you have any lucky solving this?

acuna-public commented 1 year ago

huguera10 oh, hi, I'm so sorry for forget to answer, I found out that Java threads are multicore out of the box, so the reason I've tried the side solutions for this is my wrong application approach: you need to do needed actions exactly in every thread, for example if you have four threads which you're using in ExecutorService for example, and you need to use the database - you need to open new connection in every thread (4 threads - 4 database connections). You can use global properties, but which store limited data types (strings, numbers etc.) but if you need to work with resources (databases, files, http etc.) - you need to work with it exactly in every thread, so you need to simply use your task manager to check if all your cores is working when your script is working (you can start it in infinite loop for test), if it not - you need to check your application structure and check it again.