Reduce Repo Traffic - Pre Deploy-Build and Offline Execution » History » Version 6
Henning Blohm, 30.12.2021 22:14
| 1 | 1 | Henning Blohm | h1. Reduce Repo Traffic - Pre Deploy-Build and Offline Execution |
|---|---|---|---|
| 2 | |||
| 3 | As a principle, a z2 installation is made to check for updates at startup and on-demand. After installation of the core however initial repository access may overwhelm the repository infrastructure leading to reduced scale out performance. In other cases repository access from a live installation is not desired. |
||
| 4 | |||
| 5 | h2. Example Problems |
||
| 6 | |||
| 7 | * You have large Git Repos and initial cloning by the system takes long |
||
| 8 | * You use the Maven Component Repository and do not want live-systems to download from a public maven repo |
||
| 9 | * You want to use z2 in a docker image for scale out in e.g. Kubernetes and want to avoid lengthy initialization times |
||
| 10 | * You want to always run live systems in offline mode, and rather than having z2 fetch updates, build a complete z2 installation for distribution |
||
| 11 | |||
| 12 | All of these cases are made up from a mix of the following concerns: |
||
| 13 | |||
| 14 | 4 | Henning Blohm | # Initialization time and network usage of a fresh core instance |
| 15 | # Avoiding access to remote systems at runtime |
||
| 16 | 1 | Henning Blohm | |
| 17 | h2. Reduce Initialization Time and Network Usage of a Clean Z2-Home Installation |
||
| 18 | |||
| 19 | h3. Pre-Deploy Build |
||
| 20 | |||
| 21 | Assuming you want to quickly scale out and start up instances without requiring downloading of resources it is simplest to actually build a "warm" z2-core by retrieving all component resources and possibly even prebuilding all Java components. For example, this could be the last step of preparation of a docker image for distribution. |
||
| 22 | |||
| 23 | See below Appendix 1 for a code sample. |
||
| 24 | |||
| 25 | 4 | Henning Blohm | h4. Pros: |
| 26 | 5 | Henning Blohm | |
| 27 | 1 | Henning Blohm | * Simple to implement and fits nicely to a docker setup |
| 28 | 2 | Henning Blohm | * When using the system in online mode, this combines the best of both worlds: |
| 29 | ** Quick initialization due to the pre-deployment build |
||
| 30 | ** Automatic updates by simple restarts (of e.g. docker containers) |
||
| 31 | 1 | Henning Blohm | |
| 32 | 4 | Henning Blohm | h4. Cons: |
| 33 | 5 | Henning Blohm | |
| 34 | 1 | Henning Blohm | * Image could still be large, if repos hold a lot of unused content/history |
| 35 | |||
| 36 | h3. Hub CR |
||
| 37 | |||
| 38 | Another way of generally reducing and optimizing resource retrieval for a larger distributed system is to use the Hub Component Repository (see [[How_to_use_the_hub_cr]]). In essence, your system will have different target states depending on whether it is used on a development scenario or for production. In the latter case, the Hub CR would be used and otherwise regular source code repositories would be used - controlled by e.g. environment vars. This approach can be combined with the Pre-Deploy Build. |
||
| 39 | |||
| 40 | 5 | Henning Blohm | h4. Pros: |
| 41 | |||
| 42 | 1 | Henning Blohm | * Only what is needed is retrieved - optionally pre-compiled |
| 43 | |||
| 44 | h4. Cons: |
||
| 45 | 5 | Henning Blohm | |
| 46 | 1 | Henning Blohm | * Non-Trivial repo or target state configuration depending on scenarios |
| 47 | * Requires a Hub setup and installation. Another central piece of infrastructure. |
||
| 48 | |||
| 49 | h3. SFTPSSH Repo |
||
| 50 | |||
| 51 | Finally, another approach would be to use the [[SFTPSSH_Component_Repository]] (that has not been implemented as of now). |
||
| 52 | |||
| 53 | h4. Pros: |
||
| 54 | 5 | Henning Blohm | |
| 55 | 1 | Henning Blohm | * Nodes only download what is needed - in pre-packaged form |
| 56 | * Simple to setup and maintain. No active infrastructure besides some SFTP location. |
||
| 57 | |||
| 58 | h4. Cons: |
||
| 59 | 5 | Henning Blohm | |
| 60 | 1 | Henning Blohm | * Non-Trivial repo or target state configuration depending on scenarios |
| 61 | 2 | Henning Blohm | |
| 62 | h2. Avoiding Remote Access from Live Nodes |
||
| 63 | |||
| 64 | 3 | Henning Blohm | In combination with the pre-deployment approach from above, configuring the [[V29-Reference#Using-the-Offline-Mode|offline mode]] would make sure that nodes do not attempt to access remote repositories. |
| 65 | 2 | Henning Blohm | |
| 66 | This is particularly interesting when using the [[V29-Reference#Maven-Repository-Support|Maven Component Repository]] and you want to avoid unmanaged access to remote source. In that case, anyway, it would be advisable to run a local artifact repository such as Artifactory. |
||
| 67 | 6 | Henning Blohm | |
| 68 | h2. Appendix 1: Pre-Deployment Build |
||
| 69 | |||
| 70 | A simple [[V29-Reference#Main-Program-Components-core|main program]] component to prepare all component resources and to optionally build all Java components would look like this: |
||
| 71 | |||
| 72 | <pre><code class="java"> |
||
| 73 | /** |
||
| 74 | * A simple script to prepare all repos for offline operation by retrieving all components. |
||
| 75 | * |
||
| 76 | * Pass "compile" as command line parameter to also pre-compile all Java components. |
||
| 77 | */ |
||
| 78 | public class Preparer { |
||
| 79 | private final static Logger LOG = Logger.getLogger(Preparer.class.getName()); |
||
| 80 | |||
| 81 | public static void main(String[] args) throws Exception { |
||
| 82 | boolean compile = Arrays.stream(args).filter("compile"::equals).findAny().isPresent(); |
||
| 83 | if (compile) { |
||
| 84 | LOG.info("Compiling Java components"); |
||
| 85 | } |
||
| 86 | // find all components and retrieve |
||
| 87 | IComponentsManager cm = IComponentsManager.INSTANCE; |
||
| 88 | IResourceLookup cl = IComponentsLookup.INSTANCE; |
||
| 89 | int retrieved = 0; |
||
| 90 | int compiled = 0; |
||
| 91 | for (String cn : cm.findComponents(X.val(true))) { |
||
| 92 | try { |
||
| 93 | if (cm.retrieve(cn)!=null) { |
||
| 94 | LOG.log(Level.INFO,"Retrieved {0}",cn); |
||
| 95 | retrieved++; |
||
| 96 | if (compile && IJavaComponent.TYPE.equals(cm.getComponent(cn).getType())) { |
||
| 97 | cl.lookup(cn, IJavaComponent.class); |
||
| 98 | LOG.log(Level.INFO,"Compiled {0}",cn); |
||
| 99 | compiled++; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } catch (Exception e) { |
||
| 103 | LOG.log(Level.SEVERE,"Failed to handle "+cn, e); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | LOG.log(Level.INFO,"Retrieved resources of {0} components",retrieved); |
||
| 107 | if (compile) { |
||
| 108 | LOG.log(Level.INFO,"Compiled {0} Java components",compiled); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | } |
||
| 113 | </code></pre> |
||
| 114 | |||
| 115 | Provided this is implemented with component @tools/preDeployment@, a command line executed in @$Z2_HOME/bin@ would be |
||
| 116 | |||
| 117 | <pre><code class="bash"> |
||
| 118 | java -Dcom.zfabrik.offline=false -DcomponentName=tools/preDeployment -cp z.jar com.zfabrik.launch.MainRunner compile |
||
| 119 | </code></pre> |
