def _ith_in_node(worker_id, worker_num_dict):
    """
    .. code-block: python
        >>> worker_num_dict = {('node0', 10000): 0, ('node0', 10001): 1, ('node1', 10000): 2, ('node0', 10002): 3}
        >>> _ith_in_node(('node0', 10002), worker_num_dict)
        2
        >>> _ith_in_node(('node1', 10000), worker_num_dict)
        0
    """
    node = worker_id[0]
    i    = 0
    for w, num in sorted(worker_num_dict.items(), key=lambda num: num[1]):
        if w == worker_id:
            return i
        if w[0] == node:
            i += 1
    raise KeyError('"%s:%s" does not in `worker_num_dict`: %s' % (worker_id[0], worker_id[1], worker_num_dict))