| 30308 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.dao.model.ImeiActivationTimestampModel;
|
|
|
4 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
| 30353 |
amit.gupta |
5 |
import org.apache.logging.log4j.LogManager;
|
|
|
6 |
import org.apache.logging.log4j.Logger;
|
| 30308 |
amit.gupta |
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.stereotype.Component;
|
|
|
9 |
|
| 37447 |
amit |
10 |
import java.util.ArrayList;
|
| 30308 |
amit.gupta |
11 |
import java.util.List;
|
|
|
12 |
import java.util.stream.Collectors;
|
|
|
13 |
|
|
|
14 |
@Component
|
|
|
15 |
public class StandAlone {
|
|
|
16 |
|
|
|
17 |
@Autowired
|
| 30352 |
amit.gupta |
18 |
private OppoImeiActivationService oppoImeiActivationService;
|
| 30308 |
amit.gupta |
19 |
|
|
|
20 |
@Autowired
|
| 34418 |
amit.gupta |
21 |
private RealmeImeiActivationService realmeImeiActivationService;
|
|
|
22 |
|
|
|
23 |
@Autowired
|
| 30352 |
amit.gupta |
24 |
private ActivatedImeiRepository activatedImeiRepository;
|
| 30308 |
amit.gupta |
25 |
|
| 30353 |
amit.gupta |
26 |
private static final Logger LOGGER = LogManager.getLogger(StandAlone.class);
|
|
|
27 |
|
| 30308 |
amit.gupta |
28 |
public void checkOppoImeiStatus() throws Exception {
|
| 37446 |
amit |
29 |
List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectImeiActivationPendingByBrand("Oppo", 4, 10);
|
| 30308 |
amit.gupta |
30 |
List<String> imeis = imeiActivationTimestampModels.stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
| 36253 |
amit |
31 |
LOGGER.info("Oppo secondary imeis {}", imeis);
|
| 30352 |
amit.gupta |
32 |
oppoImeiActivationService.updateActivationDate(imeis);
|
| 30308 |
amit.gupta |
33 |
}
|
| 34418 |
amit.gupta |
34 |
|
| 36253 |
amit |
35 |
public void checkOppoImeiStatusTertiary() throws Exception {
|
| 37446 |
amit |
36 |
List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectImeiActivationPendingByBrandTertiary("Oppo", 2, 10);
|
| 36253 |
amit |
37 |
List<String> imeis = imeiActivationTimestampModels.stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
|
|
38 |
LOGGER.info("Oppo tertiary imeis {}", imeis);
|
|
|
39 |
oppoImeiActivationService.updateActivationDate(imeis);
|
|
|
40 |
}
|
|
|
41 |
|
| 34418 |
amit.gupta |
42 |
public void checkRealmeImeiStatus() throws Exception {
|
| 37446 |
amit |
43 |
List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectImeiActivationPendingByRealme("Realme", 4, 10);
|
| 34418 |
amit.gupta |
44 |
List<String> imeis = imeiActivationTimestampModels.stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
| 36253 |
amit |
45 |
LOGGER.info("Realme secondary imeis {}", imeis);
|
| 34418 |
amit.gupta |
46 |
realmeImeiActivationService.updateActivationDate(imeis);
|
|
|
47 |
}
|
| 36253 |
amit |
48 |
|
|
|
49 |
public void checkRealmeImeiStatusTertiary() throws Exception {
|
| 37446 |
amit |
50 |
List<ImeiActivationTimestampModel> imeiActivationTimestampModels = activatedImeiRepository.selectImeiActivationPendingByBrandTertiary("Realme", 2, 10);
|
| 36253 |
amit |
51 |
List<String> imeis = imeiActivationTimestampModels.stream().map(x -> x.getSerialNumber()).collect(Collectors.toList());
|
|
|
52 |
LOGGER.info("Realme tertiary imeis {}", imeis);
|
|
|
53 |
realmeImeiActivationService.updateActivationDate(imeis);
|
|
|
54 |
}
|
| 37447 |
amit |
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 |
|
| 36253 |
amit |
121 |
}
|