public static <SERVICE extends AbstractService> void distributeCpuSocketAffinity(Collection<SERVICE> services) {
        Map<HostResource, List<SERVICE>> affinityMap = new HashMap<>();
        for (SERVICE service : services) {
            if (!affinityMap.containsKey(service.getHostResource())) {
                affinityMap.put(service.getHostResource(), new ArrayList<>());
            }
            int cpuSocket = affinityMap.get(service.getHostResource()).size();
            affinityMap.get(service.getHostResource()).add(service);
            service.setAffinity(new Affinity.Builder().cpuSocket(cpuSocket).build());
        }
    }
Distribute affinity on a collection of services. Services that are located on the same host
will be assigned a specific cpu socket on that host.

@param services A {@link Collection} of services of the same type, not necessarily on the same host.
config-model/src/main/java/com/yahoo/vespa/model/AbstractService.java