Ejemplo n.º 1
0
int
getNumThreads (rsComm_t *rsComm, rodsLong_t dataSize, int inpNumThr,
               keyValPair_t *condInput, char *destRescName, char *srcRescName)
{
    ruleExecInfo_t rei;
    dataObjInp_t doinp;
    int status;
    int numDestThr = -1;
    int numSrcThr = -1;
    rescGrpInfo_t *rescGrpInfo;

    if (inpNumThr == NO_THREADING)
        return 0;

    if (dataSize < 0)
        return 0;

    if (dataSize <= MIN_SZ_FOR_PARA_TRAN) {
        if (inpNumThr > 0) {
            inpNumThr = 1;
        } else {
            return 0;
        }
    }

    if (getValByKey (condInput, NO_PARA_OP_KW) != NULL) {
        /* client specify no para opr */
        return (1);
    }

#ifndef PARA_OPR
    return (1);
#endif

    memset (&doinp, 0, sizeof (doinp));
    doinp.numThreads = inpNumThr;

    doinp.dataSize = dataSize;

    initReiWithDataObjInp (&rei, rsComm, &doinp);

    if (destRescName != NULL) {
        rescGrpInfo = NULL;
        status = resolveAndQueResc (destRescName, NULL, &rescGrpInfo);
        if (status >= 0) {
            rei.rgi = rescGrpInfo;
            status = applyRule ("acSetNumThreads", NULL, &rei, NO_SAVE_REI);
            freeRescGrpInfo (rescGrpInfo);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                         "getNumThreads: acGetNumThreads error, status = %d",
                         status);
            } else {
                numDestThr = rei.status;
                if (numDestThr == 0) {
                    return 0;
                } else if (numDestThr == 1 && srcRescName == NULL &&
                           isLocalHost (rescGrpInfo->rescInfo->rescLoc)) {
                    /* one thread and resouce on local host */
                    return 0;
                }
            }
        }
    }

    if (srcRescName != NULL) {
        if (numDestThr > 0 && strcmp (destRescName, srcRescName) == 0)
            return numDestThr;
        rescGrpInfo = NULL;
        status = resolveAndQueResc (srcRescName, NULL, &rescGrpInfo);
        if (status >= 0) {
            rei.rgi = rescGrpInfo;
            status = applyRule ("acSetNumThreads", NULL, &rei, NO_SAVE_REI);
            freeRescGrpInfo (rescGrpInfo);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                         "getNumThreads: acGetNumThreads error, status = %d",
                         status);
            } else {
                numSrcThr = rei.status;
                if (numSrcThr == 0) return 0;
            }
        }
    }

    /* At this point, number of threads for both source and destination
       have been set based on acSetNumThreads policy point, and neither
       of them are set to 0 (to turn off threading). If both numDestThr
       and numSrcThr are set, choose the smallest one. The reasoning is
       that acSetNumThreads is used by a site to limit the default
       maximum parallel threads, so we should honor the most restrictive
       setting. */
    if (numDestThr > 0 && numSrcThr > 0) {
        if (getValByKey (condInput, RBUDP_TRANSFER_KW) != NULL) {
            return 1;
        } else if (numDestThr < numSrcThr) {
            return numDestThr;
        } else {
            return numSrcThr;
        }
    }
    if (numDestThr > 0) {
        if (getValByKey (condInput, RBUDP_TRANSFER_KW) != NULL) {
            return 1;
        } else {
            return numDestThr;
        }
    }
    if (numSrcThr > 0) {
        if (getValByKey (condInput, RBUDP_TRANSFER_KW) != NULL) {
            return 1;
        } else {
            return numSrcThr;
        }
    }
    /* should not be here. do one with no resource */
    rei.rgi = NULL;
    status = applyRule ("acSetNumThreads", NULL, &rei, NO_SAVE_REI);
    if (status < 0) {
        rodsLog (LOG_ERROR,
                 "getNumThreads: acGetNumThreads error, status = %d",
                 status);
        return 0;
    } else {
        if (rei.status > 0)
            return rei.status;
        else
            return 0;
    }
}
Ejemplo n.º 2
0
int
getNumThreads (rsComm_t *rsComm, rodsLong_t dataSize, int inpNumThr,
               keyValPair_t *condInput, char *destRescName, char *srcRescName)
{
    ruleExecInfo_t rei;
    dataObjInp_t doinp;
    int status;
    int numDestThr = -1;
    int numSrcThr = -1;
    rescGrpInfo_t *rescGrpInfo;

    if (inpNumThr == NO_THREADING)
        return 0;

    if (dataSize < 0)
        return 0;

    if (dataSize <= MIN_SZ_FOR_PARA_TRAN) {
        if (inpNumThr > 0) {
            inpNumThr = 1;
        } else {
            return 0;
        }
    }

    if (getValByKey (condInput, NO_PARA_OP_KW) != NULL) {
        /* client specify no para opr */
        return (1);
    }

#ifndef PARA_OPR
    return (1);
#endif

    memset (&doinp, 0, sizeof (doinp));
    doinp.numThreads = inpNumThr;

    doinp.dataSize = dataSize;

    initReiWithDataObjInp (&rei, rsComm, &doinp);

    if (destRescName != NULL) {
        rescGrpInfo = NULL;
        status = resolveAndQueResc (destRescName, NULL, &rescGrpInfo);
        if (status >= 0) {
            rei.rgi = rescGrpInfo;
            status = applyRule ("acSetNumThreads", NULL, &rei, NO_SAVE_REI);
            freeRescGrpInfo (rescGrpInfo);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                         "getNumThreads: acGetNumThreads error, status = %d",
                         status);
            } else {
                numDestThr = rei.status;
                if (numDestThr == 0) {
                    return 0;
                } else if (numDestThr == 1 && srcRescName == NULL &&
                           isLocalHost (rescGrpInfo->rescInfo->rescLoc)) {
                    /* one thread and resouce on local host */
                    return 0;
                }
            }
        }
    }

    if (srcRescName != NULL) {
        if (numDestThr > 0 && strcmp (destRescName, srcRescName) == 0)
            return numDestThr;
        rescGrpInfo = NULL;
        status = resolveAndQueResc (srcRescName, NULL, &rescGrpInfo);
        if (status >= 0) {
            rei.rgi = rescGrpInfo;
            status = applyRule ("acSetNumThreads", NULL, &rei, NO_SAVE_REI);
            freeRescGrpInfo (rescGrpInfo);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                         "getNumThreads: acGetNumThreads error, status = %d",
                         status);
            } else {
                numSrcThr = rei.status;
                if (numSrcThr == 0) return 0;
            }
        }
    }

    if (numDestThr > 0) {
        if (getValByKey (condInput, RBUDP_TRANSFER_KW) != NULL) {
            return 1;
        } else {
            return numDestThr;
        }
    }
    if (numSrcThr > 0) {
        if (getValByKey (condInput, RBUDP_TRANSFER_KW) != NULL) {
            return 1;
        } else {
            return numSrcThr;
        }
    }
    /* should not be here. do one with no resource */
    rei.rgi = NULL;
    status = applyRule ("acSetNumThreads", NULL, &rei, NO_SAVE_REI);
    if (status < 0) {
        rodsLog (LOG_ERROR,
                 "getNumThreads: acGetNumThreads error, status = %d",
                 status);
        return 0;
    } else {
        if (rei.status > 0)
            return rei.status;
        else
            return 0;
    }
}