Subversion Repositories SmartDukaan

Rev

Rev 37446 | Rev 37448 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37446 Rev 37447
Line 5... Line 5...
5
import org.apache.logging.log4j.LogManager;
5
import org.apache.logging.log4j.LogManager;
6
import org.apache.logging.log4j.Logger;
6
import org.apache.logging.log4j.Logger;
7
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.stereotype.Component;
8
import org.springframework.stereotype.Component;
9
 
9
 
-
 
10
import java.util.ArrayList;
10
import java.util.List;
11
import java.util.List;
11
import java.util.stream.Collectors;
12
import java.util.stream.Collectors;
12
 
13
 
13
@Component
14
@Component
14
public class StandAlone {
15
public class StandAlone {
Line 49... Line 50...
49
		List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectImeiActivationPendingByBrandTertiary("Realme", 2, 10);
50
		List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectImeiActivationPendingByBrandTertiary("Realme", 2, 10);
50
		List<String> imeis = imeiActivationTimestampModels.stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
51
		List<String> imeis = imeiActivationTimestampModels.stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
51
		LOGGER.info("Realme tertiary imeis {}", imeis);
52
		LOGGER.info("Realme tertiary imeis {}", imeis);
52
		realmeImeiActivationService.updateActivationDate(imeis);
53
		realmeImeiActivationService.updateActivationDate(imeis);
53
	}
54
	}
-
 
55
 
-
 
56
	/**
-
 
57
	 * Secondary + tertiary in ONE browser session per brand.
-
 
58
	 *
-
 
59
	 * They were separate @Scheduled jobs, so each brand span up two ChromeDrivers at
-
 
60
	 * once and the fleet ran four. Each driver tree costs roughly 850MB, and this box
-
 
61
	 * co-hosts a 9.4GB tomcat with ~3GB available -- it has been OOM-killed twice this
-
 
62
	 * month and tomcat was the victim both times. Halving concurrent drivers is the
-
 
63
	 * single biggest memory saving available here.
-
 
64
	 *
-
 
65
	 * Nothing else changes: the two pools differ only in which named query fills them,
-
 
66
	 * and both already funnel into the same updateActivationDate -> checkWarranty ->
-
 
67
	 * saveActivation path. The pools are disjoint by construction (secondary excludes
-
 
68
	 * anything with a FofoLineItem, tertiary is FofoLineItem-based); distinct() is cheap
-
 
69
	 * insurance rather than a fix for a known overlap.
-
 
70
	 *
-
 
71
	 *
-
 
72
	 * Sizing: merging SERIALISES work that used to run in parallel, so keeping the old
-
 
73
	 * batch sizes would cost throughput. Measured post-cap at 10.2s/imei (oppo) and
-
 
74
	 * 14.2s/imei (realme), solving M * 86400 / (300 + M*t):
-
 
75
	 *   oppo    2 parallel jobs x10 = 4,299/day  ->  merged 30 = 4,277/day  (parity)
-
 
76
	 *   realme  2 parallel jobs x10 = 3,910/day  ->  merged 20 = 2,959/day  (-24%)
-
 
77
	 * Oppo is sized to hold parity because it is already short of its 4,798/day need.
-
 
78
	 * Realme is left at 20 -- it needs 2,243/day, so it can absorb the dip in exchange
-
 
79
	 * for shorter batches.
-
 
80
	 *
-
 
81
	 * Note what this does and does not save: total driver-SECONDS are unchanged (that is
-
 
82
	 * the point of resizing), but PEAK concurrent drivers halves from 4 to 2. Peak is
-
 
83
	 * what triggers the OOM killer, not average.
-
 
84
	 *
-
 
85
	 * The per-pool log lines are kept so existing log analysis still works.
-
 
86
	 */
-
 
87
	public void checkOppoImeiStatusCombined() throws Exception {
-
 
88
		List<String> secondary = activatedImeiRepository.selectImeiActivationPendingByBrand("Oppo", 4, 15)
-
 
89
				.stream().map(ImeiActivationTimestampModel::getSerialNumber).collect(Collectors.toList());
-
 
90
		List<String> tertiary = activatedImeiRepository.selectImeiActivationPendingByBrandTertiary("Oppo", 2, 15)
-
 
91
				.stream().map(ImeiActivationTimestampModel::getSerialNumber).collect(Collectors.toList());
-
 
92
		LOGGER.info("Oppo secondary imeis {}", secondary);
-
 
93
		LOGGER.info("Oppo tertiary imeis {}", tertiary);
-
 
94
		List<String> all = new ArrayList<>(secondary);
-
 
95
		all.addAll(tertiary);
-
 
96
		all = all.stream().distinct().collect(Collectors.toList());
-
 
97
		if (all.isEmpty()) {
-
 
98
			LOGGER.info("Oppo: nothing pending, not starting a browser");
-
 
99
			return;
-
 
100
		}
-
 
101
		oppoImeiActivationService.updateActivationDate(all);
-
 
102
	}
-
 
103
 
-
 
104
	public void checkRealmeImeiStatusCombined() throws Exception {
-
 
105
		List<String> secondary = activatedImeiRepository.selectImeiActivationPendingByRealme("Realme", 4, 10)
-
 
106
				.stream().map(ImeiActivationTimestampModel::getSerialNumber).collect(Collectors.toList());
-
 
107
		List<String> tertiary = activatedImeiRepository.selectImeiActivationPendingByBrandTertiary("Realme", 2, 10)
-
 
108
				.stream().map(ImeiActivationTimestampModel::getSerialNumber).collect(Collectors.toList());
-
 
109
		LOGGER.info("Realme secondary imeis {}", secondary);
-
 
110
		LOGGER.info("Realme tertiary imeis {}", tertiary);
-
 
111
		List<String> all = new ArrayList<>(secondary);
-
 
112
		all.addAll(tertiary);
-
 
113
		all = all.stream().distinct().collect(Collectors.toList());
-
 
114
		if (all.isEmpty()) {
-
 
115
			LOGGER.info("Realme: nothing pending, not starting a browser");
-
 
116
			return;
-
 
117
		}
-
 
118
		realmeImeiActivationService.updateActivationDate(all);
-
 
119
	}
-
 
120
 
54
}
121
}