* BackoffSweeper() looks at all the backend structures to determine if any * backends are not making progress. This is done by inspecting the lastchecked * time. It also calculates the total weight of all 'active' backends to * re-calculate the target CPU usage per backend process. If it finds that a * backend is trying to request more CPU resources than the maximum CPU that it * can get (su
| 698 | * active backends belonging to the query. |
| 699 | */ |
| 700 | void |
| 701 | BackoffSweeper() |
| 702 | { |
| 703 | int i = 0; |
| 704 | |
| 705 | /* The overall weight of active statements */ |
| 706 | volatile double activeWeight = 0.0; |
| 707 | int numActiveBackends = 0; |
| 708 | int numActiveStatements = 0; |
| 709 | |
| 710 | /* The overall weight of active and inactive statements */ |
| 711 | int totalStatementWeight = 0; |
| 712 | int numValidBackends = 0; |
| 713 | int numStatements = 0; |
| 714 | |
| 715 | struct timeval currentTime; |
| 716 | |
| 717 | if (gettimeofday(¤tTime, NULL) < 0) |
| 718 | { |
| 719 | elog(ERROR, "Unable to execute gettimeofday(). Please disable query prioritization."); |
| 720 | } |
| 721 | |
| 722 | Assert(backoffSingleton->sweeperInProgress == false); |
| 723 | |
| 724 | backoffSingleton->sweeperInProgress = true; |
| 725 | |
| 726 | TRACE_POSTGRESQL_BACKOFF_GLOBALCHECK(); |
| 727 | |
| 728 | /* Reset status for all the backend entries */ |
| 729 | for (i = 0; i < backoffSingleton->numEntries; i++) |
| 730 | { |
| 731 | BackoffBackendSharedEntry *se = getBackoffEntryRW(i); |
| 732 | |
| 733 | se->isActive = false; |
| 734 | se->numFollowersActive = 0; |
| 735 | se->backoff = true; |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * Mark backends that are active. Count of active group members is |
| 740 | * maintained at their group leader. |
| 741 | */ |
| 742 | for (i = 0; i < backoffSingleton->numEntries; i++) |
| 743 | { |
| 744 | BackoffBackendSharedEntry *se = getBackoffEntryRW(i); |
| 745 | |
| 746 | if (isValid(&se->statementId)) |
| 747 | { |
| 748 | Assert(se->weight > 0); |
| 749 | if (TIMEVAL_DIFF_USEC(currentTime, se->lastCheckTime) |
| 750 | < gp_resqueue_priority_inactivity_timeout * 1000.0) |
| 751 | { |
| 752 | /* |
| 753 | * This is an active backend. Need to maintain count at group |
| 754 | * leader |
| 755 | */ |
| 756 | BackoffBackendSharedEntry *gl = getBackoffEntryRW(se->groupLeaderIndex); |
| 757 |
no test coverage detected