30 December 2019

Pro Perl Programming

Technical Reviewed

© 2020
Pro Perl Programming
From Professional to Advanced
Authors: Rothwell, William \Bo\

https://www.apress.com/gp/book/9781484256046



18 December 2019

-XX:NewRatio

from: https://blog.codecentric.de/en/2012/08/useful-jvm-flags-part-5-young-generation-garbage-collection/


-XX:NewRatio

It is also possible to specify the young generation size in relation to the size of the old generation. The potential advantage of this approach is that the young generation will grow and shrink automatically when the JVM dynamically adjusts the total heap size at run time. The flag -XX:NewRatio allows us to specify the factor by which the old generation should be larger than the young generation. For example, with -XX:NewRatio=3 the old generation will be three times as large as the young generation. That is, the old generation will occupy 3/4 and the young generation will occupy 1/4 of the heap.
If we mix absolute and relative sizing of the young generation, the absolute values always have precedence. Consider the following example:

$ java -XX:NewSize=32m -XX:MaxNewSize=512m -XX:NewRatio=3 MyApp
 
With these settings, the JVM will try to size the young generation at one third of the old generation size, but it will never let young generation size fall below 32 MB or exceed 512 MB.
There is no general rule if absolute or relative young generation sizing is preferable. If we know the memory usage of our application well, it can be advantageous to specify a fixed size both for the total heap and the young generation, and it can also be useful to specify a ratio. If we only know a little or maybe nothing at all about our application in this respect, the correct approach is to just let the JVM do the work and not to mess around with the flags. If the application runs smoothly, we can be happy that we didn’t put in extra effort where none was needed. And should we encounter performance problems or OutOfMemoryErrors, we would still need to first perform a series of meaningful measurements to narrow down the root cause of the problem before moving on to tuning.

03 December 2019

Pipeline Pattern

Many times we need to implement a workflow/pipeline in our code (i.e.: Java) this brings us bad design by using too many nested loops, if/switch, etc.

One way is to use a BPM however this has boilerplate config/code, a leaner solution is to implement Pipeline Pattern:

Definition of the Pipeline Pattern

 Each of the sequence of calculations is performed by having the first stage of the pipeline perform the first step, and then the second stage the second step, and so on.
 As each stage completes a step of a calculation, it passes the calculation-in-progress to the next stage and begins work on the next calculation.”


https://www.cise.ufl.edu/research/ParallelPatterns/PatternLanguage/AlgorithmStructure/Pipeline.htm

This is almost the same than:

Pipeline, Pipes and filters:

https://www.enterpriseintegrationpatterns.com/patterns/messaging/PipesAndFilters.html

https://www.codeproject.com/articles/1094513/pipeline-and-filters-pattern-using-csharp




gist:
https://stackoverflow.com/questions/39947155/pipeline-design-pattern-implementation

Spring contexts and Servlets


applicationContext.xml defines the beans for the "root webapp context", i.e. the context associated with the webapp. This means is transversal.

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
 


The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet's app context. There can be many of these in a webapp, one per Spring servlet (e.g. spring1-servlet.xml for servlet spring1, spring2-servlet.xml for servlet spring2).

Therefore resources that need to be injected transversal can be set in applicationContext.xml, ie:

  <import resource="classpath*:spring/jwt-security-context.xml"/>
  

from: https://stackoverflow.com/questions/3652090/difference-between-applicationcontext-xml-and-spring-servlet-xml-in-spring-frame



Also Servelts using Spring DI:

- https://stackoverflow.com/questions/35255052/spring-service-not-injected-in-web-servlet
- http://www.javavillage.in/spring-ioc-on-servlets.php

26 November 2019

Debugging Linux Tools

A good summary of debugging Linux tools:

  1. 'print' statements
  2. Querying (/proc, /sys etc)
  3. Tracing (strace/ltrace)
  4. Valgrind (memwatch)
  5. GDB

at: https://linoxide.com/linux-how-to/user-space-debugging-tools-linux/

22 November 2019

Spring Classpath

SIMPLE DEFINITION

The classpath*:conf/appContext.xml simply means that all appContext.xml files under conf folders in all your jars on the classpath will be picked up and joined into one big application context.

In contrast, classpath:conf/appContext.xml will load only one such file... the first one found on your classpath.

12 November 2019

TAOCP: Volume 4B, Fascicle 5

The Art of Computer Programming, Volume 4B, Fascicle 5: Mathematical Preliminaries Redux; Introduction to Backtracking; Dancing Links

This fascicle covers three separate topics:
  1.  Mathematical Preliminaries. Knuth writes that this portion of fascicle 5 "extends the ‘Mathematical Preliminaries’ of Section 1.2 in Volume 1 to things that I didn't know about in the 1960s. Most of this new material deals with probabilities and expectations of random events; there's also an introduction to the theory of martingales."
  2.  Backtracking: this section is the counterpart to section 7.2.1 which covered the generation of basic combinatorial patterns. This section covers non-basic patterns, ones where the developer needs to make tentative choices and then may need to backtrack when those choices need revision.
  3.  Dancing Links: this section is related to 2 above. It develops an important data structure technique that is suitable for backtrack programming described above.




04 November 2019

BEA-141297

Cuando se baja de forma incorrecta el AdminServer:

<Info> <Management> <BEA-141297> <Could not get the server file lock. Ensure that another server is not running in the same directory. Retrying for another 60 seconds.>

Hay que borrar :

/mdw/domains/base_domain/servers/AdminServer/tmp/AdminServer.lok


08 October 2019

Parsing tools


Many times I've seen the necessity for parser creation. There are many examples where we need a parser for automation of analysis, diagram creation, etc.

Most common libraries for it :

  1. antlr
  2. javaparser
  3. eclipse jdt
  4. custom

Own example: https://github.com/devwebcl/eclipse-cdt-poc


Examples :


  1. Documenting your architecture: Wireshark, PlantUML and a REPL to glue them all
  2. Your Program as a Transpiler
  3. Federico Tomassetti has several DSL examples.



27 September 2019

Deuda Técnica

https://en.wikipedia.org/wiki/Technical_debt
https://www.martinfowler.com/bliki/TechnicalDebt.html
https://martinfowler.com/bliki/TechnicalDebtQuadrant.html
https://sites.google.com/site/unclebobconsultingllc/a-mess-is-not-a-technical-debt

A mess is not a technical debt. A mess is just a mess. Technical debt decisions are made based on real project constraints. They are risky, but they can be beneficial. The decision to make a mess is never rational, is always based on laziness and unprofessionalism, and has no chance of paying of in the future. A mess is always a loss. (Uncle Bob)

contraponen:

https://hackernoon.com/there-are-3-main-types-of-technical-debt-heres-how-to-manage-them-4a3328a4c50c


En los 2 primeros ejemplos de Dag, la deuda tecnica siempre se basa en un diseño profesional y correcto, no la flojera o al no-profesionalismo que Uncle Bob describe.

I agree with Uncle Bob that this is usually a reckless debt, because people underestimate where the DesignPayoffLine is.

https://martinfowler.com/bliki/DesignStaminaHypothesis.html

hay 2 curvas por agregar deuda tecnica y time to market.

al final el buen diseño es para obtener mas rapidez en el desarrollo (y mejor calidad).

JVM CPU

Thread CPU time

A Java virtual machine implementation may support measuring the CPU time for the current thread, for any thread, or for no threads.The isThreadCpuTimeSupported() method can be used to determine if a Java virtual machine supports measuring of the CPU time for any thread. The isCurrentThreadCpuTimeSupported() method can be used to determine if a Java virtual machine supports measuring of the CPU time for the current thread. A Java virtual machine implementation that supports CPU time measurement for any thread will also support that for the current thread.
The CPU time provided by this interface has nanosecond precision but not necessarily nanosecond accuracy.
A Java virtual machine may disable CPU time measurement by default. The isThreadCpuTimeEnabled() and setThreadCpuTimeEnabled(boolean) methods can be used to test if CPU time measurement is enabled and to enable/disable this support respectively. Enabling thread CPU measurement could be expensive in some Java virtual machine implementations.

https://docs.oracle.com/javase/7/docs/api/java/lang/management/ThreadMXBean.html#getThreadCpuTime(long)


ThreadMXBean.getThreadCpuTime()

https://github.com/devwebcl/jdk7u-jdk/blob/master/src/share/classes/java/lang/management/ThreadMXBean.java


https://github.com/devwebcl/jdk7u-jdk/blob/master/src/share/classes/sun/management/ThreadImpl.java


16 September 2019

Memory Leaks: A Primer

from http://www.toptal.com/java/hunting-memory-leaks-in-java

For starters, think of memory leakage as a disease and Java’s OutOfMemoryError (OOM, for brevity) as a symptom. But as with any disease, not all OOMs necessarily imply memory leaks: an OOM can occur due to the generation of a large number of local variables or other such events. On the other hand, not all memory leaks necessarily manifest themselves as OOMs, especially in the case of desktop applications or client applications (which aren’t run for very long without restarts).

Think of memory leakage as a disease and the OutOfMemoryError as a symptom. But not all OutOfMemoryErrors imply memory leaks, and not all memory leaks manifest themselves as OutOfMemoryErrors.


12 September 2019

Eclipse MAT Classloaders


Network Troubleshooting

Summary of networking tools for troubleshooting.

  1. https://developer.ibm.com/articles/au-aixnetworkproblem1/
  2. https://www.tecmint.com/linux-network-configuration-and-troubleshooting-commands/


responsive ping

$ ping testhost
PING testhost: (10.217.1.206): 56 data bytes
64 bytes from 10.217.1.206: icmp_seq=0 ttl=253 time=0 ms
64 bytes from 10.217.1.206: icmp_seq=1 ttl=253 time=0 ms
64 bytes from 10.217.1.206: icmp_seq=2 ttl=253 time=0 ms


ping unresponsive:

$ ping testhost
PING testhost.testdomain.com: (10.216.122.12): 56 data bytes

‑‑‑‑testhost.testdomain.com PING Statistics‑‑‑‑
5 packets transmitted, 0 packets received, 100% packet loss


Displaying network adapter status

$ ifconfig en1
en1: flags=7e080863,40    CHECKSUM_OFFLOAD,CHECKSUM_SUPPORT,PSEG>
        inet 10.216.163.37 netmask 0xffffff00 broadcast 10.216.163.255
         tcp_sendspace 131072 tcp_recvspace 65536

$ifconfig ‑a
en2: flags=7e080863,40
      CHECKSUM_OFFLOAD,CHECKSUM_SUPPORT,PSEG>
        inet 10.203.35.14 netmask 0xffffff80 broadcast 10.203.35.127
en1: flags=7e080863,40
    CHECKSUM_OFFLOAD,CHECKSUM_SUPPORT,PSEG>
        inet 10.216.163.37 netmask 0xffffff00 broadcast 10.216.163.




Displaying Ethernet statistics for a network adapter
   
$ entstat ‑d en2
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
ETHERNET STATISTICS (en2) :
Device Type: 10/100/1000 Base‑TX PCI‑X Adapter (14106902)
Hardware Address: 00:02:55:d3:37:be
Elapsed Time: 114 days 22 hours 48 minutes 20 seconds

Transmit Statistics:           Receive Statistics:
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑           ‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
Packets: 490645639             Packets: 3225432063
Bytes: 9251643184881           Bytes: 215598601362
Interrupts: 0                  Interrupts: 3144149248



Tracing a successful route to a host   

$ traceroute testhost
trying to get source for testhost
source should be 10.216.163.37
traceroute to testhost (10.217.1.206) from 10.216.163.37 (10.216.163.37), 30 hops max
outgoing MTU = 1500
 1  10.216.163.2 (10.216.163.2)  1 ms  0 ms  0 ms
 2  10.217.189.6 (10.217.189.6)  0 ms  0 ms  0 ms
 3  testhost (10.217.1.206)  1 ms  1 ms  1 ms

traceroute -p 40015 200.14.166.72


Testing port 80 (HTTP) on a host (successful)

$ telnet testhost 80
Trying...
Connected to testhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.


$ grep testhost /etc/hosts
10.217.1.206    testhost testhost.testdomain.com aixserver
 

$ curl 10.217.1.206:22
SSH-2.0-OpenSSH_7.4
curl: (56) Recv failure: Connection reset by peer




Resolving a host name via DNS

$ nslookup testhost
Server:  testdns.testdomain.com
Address:  158.177.79.90

Name:    testhost.testdomain.com
Address:  10.217.1.206

nslookup www.devweb.cl 1.1.1.1

Dig

dig @8.8.8.8 +trace stackoverflow.com

  1. https://www.digwebinterface.com/
  2. https://mxtoolbox.com/SuperTool.aspx
  3. https://dnschecker.org/#A/corporate.bcimiami.com



Get DNS Records Using dig and host Commands

You can use the dig command to verify DNS mappings, host addresses, MX records, and all other DNS records for a better understanding of DNS topography.

The dig command was developed to replace nslookup command.

$ dig google.com


Telnet without telnet:

curl -v telnet://127.0.0.1:22

cat < /dev/tcp/127.0.0.1/22


telnet: ctrl+] is an escape sequence that puts telnet into command mode,

curls cookies

curl -c - "http://127.0.0.1:7001/sample/deals-api-aggregator"

curl -c - "http://127.0.0.1:7001/sample/presentacion-0.0.1-SNAPSHOT/"

curl -v --cookie 'JSESSIONIDMULTIPRO=123' -c - "http://127.0.0.1:7001/sample/deals-api-aggregator/"


steroids:

mtr >> ping/traceroute
curl >> wget
htop >> ps/top
ncdu >> du
parallel >> xargs/ssh
rsync >> cp/scp
ag >> find/grep
dig >> nslookup


SSL test:

https://www.ssllabs.com/ssltest/analyze.html?d=github.com&s=192.30.255.112&hideResults=on

Misc

netstat -apn (linux)

nmap

netstat -apn | grep 8001

 

how to know IP :
ipconfig

ifconfig | grep "inet " | grep -v 127.0.0.1

linux:
ifconfig eth0

netstat cheat sheet 


Difference among JVM JRE JDK

JVM = responsible for executing the java program line by line hence it is also known as an interpreter.

JRE = JVM + Lib classes

JDK = JRE + Dev Tool


10 September 2019

Visitor Pattern

Two simple examples are taken from github repo about Visitor pattern:


The Visitor drops by:

  • The Visitor must visit each element of the Composite; that functionality is in a Traverser object.
  • The Visitor is guided by the Traverser to gather state from all of the objects in the Composite.
  • Once the state has been gathered, the Client can have the Visitor perform various operations on the state.
  • When new functionality is required, only the Visitor must be enhanced.

From: Head First Design Patterns.

1. https://github.com/devwebcl/simple_design_patterns/tree/master/visitor-pattern/src/main/java/com/iluwatar/visitor









2.  https://github.com/devwebcl/simple_design_patterns/tree/master/visitor-pattern/src/main/java/com/behavioural/visitor




References:


  1. https://github.com/chirey/designPatternsThoughtsCode
  2. https://github.com/iluwatar/java-design-patterns/tree/master/visitor



Java Threads API Evolution

After searching again for this cool article: https://howtodoinjava.com/java/multi-threading/java-multi-threading-evolution-and-topics/

Here there is a summary of Threads evolution through the years:

JDK 1.0

java.lang.Thread
java.lang.ThreadGroup
java.lang.Runnable
java.lang.Process
java.lang.ThreadDeath

JDK 1.1

The Thread.stop, Thread.suspend, and Thread.resume methods are deprecated as of JDK 1.1.

JDK 1.2 and JDK 1.3 

had no noticeable changes

JDK 1.4

There were few JVM level changes to suspend/resume multiple threads with single call.

JDK 1.5 

was first big release after JDK 1.x; and it had included multiple concurrency utilities. Executor/ExecutorService, semaphore, mutex, barrier, latches, concurrent collections and blocking queues;

JDK 1.6

was more of platform fixes than API upgrades.

JDK 1.7 

added support for ForkJoinPool which implemented a work-stealing technique to maximize the throughput. Also, Phaser class was added.

JDK 1.8 

is largely known for Lambda changes, but it also had few concurrency changes as well. Two new interfaces and four new classes were added in java.util.concurrent package e.g. CompletableFuture and CompletionException.

The Collections Framework has undergone a major revision in Java 8 to add aggregate operations based on the newly added streams facility and lambda expressions; resulting in a large number of methods added in almost all Collection classes, and thus in concurrent collections as well.

JDK 9

JEP 266: More Concurrency Updates defines an interoperable publish-subscribe framework for reactive streams, enhancements to the java.util.concurrent.CompletableFuture class, and various other improvements.



06 September 2019

05 September 2019

Haskell Quick Syntax Reference

Technical reviewed:

© 2019
Haskell Quick Syntax Reference
A Pocket Guide to the Language, APIs, and Library
Authors: Nita, Stefania Loredana, Mihailescu, Marius

https://www.apress.com/gp/book/9781484245064


04 September 2019

Introducing Markdown and Pandoc

Technical reviewed:

Introducing Markdown and Pandoc: Using Markup Language and Document Converter Paperback – August 20, 2019
by Thomas Mailund

https://www.apress.com/gp/book/9781484251485


02 September 2019

WebAssembly in Action

Technical reviewed:

WebAssembly in Action
With examples using C++ and Emscripten

Gerard Gallant
November 2019 ISBN 9781617295744 448 pages

https://www.manning.com/books/webassembly-in-action


29 August 2019

Java 8 parallel streams pitfall

1.
All parallel streams use a common fork-join thread pool, and if you submit a long-running task, you effectively block all threads in the pool. Consequently, you block all other tasks that are using parallel streams.

2.
The default processing that occurs in such a Stream uses the ForkJoinPool.commonPool(), a Thread Pool shared by the entire application.

3.
This way we essentially force the parallel stream to have a ForkJoin as a parent thread, instead of a regular thread, so ForkJoinPool.commonPool is not used. Hooray!

20 August 2019

Spring MVC AsyncRestTemplate

Simple example to call Async RestTemplate :

https://github.com/devwebcl/async-springmvc-poc

Most important snippet code:

public AsyncRestTemplate asyncRestTemplateFactory() {
 PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();

 connManager.setMaxTotal(maxTotalConnections);
 connManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);
 CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build();
 HttpComponentsAsyncClientHttpRequestFactory requestAsyncFactory =
 new HttpComponentsAsyncClientHttpRequestFactory();
 requestAsyncFactory.setConnectionRequestTimeout(connectRequestTimeout);
 requestAsyncFactory.setConnectTimeout(connectTimeout);
 requestAsyncFactory.setReadTimeout(readTimeout);
 requestAsyncFactory.setHttpClient(httpClient);

 AsyncRestTemplate art = new AsyncRestTemplate();
 art.setAsyncRequestFactory(requestAsyncFactory);


 //deberia ser inyectado desde DI container
 return new AsyncRestTemplate(requestAsyncFactory);
 }



and



public String callback() throws Exception {

        Map<String, ListenableFuture<ResponseEntity<String>>> futures = new HashMap<>(); //podria ser un Guava Table
        List<String> respuestas = new ArrayList<>();
       

        AsyncFactory af = new AsyncFactory();
        AsyncRestTemplate artf = af.asyncRestTemplateFactory();

        //url a visitar
        String[] url = {"http://google.com", "http://bing.com", "https://stackoverflow.com/", "https://www.infoq.com/", "https://dzone.com/",
                        "https://jakarta.ee/", "https://www.eclipse.org/",  "http://www.noexisto.cl/", "https://spring.io/", "https://github.com/",
                        "https://www.apache.org/"};

       
        //agrego llamadas asincronas
        for(int i=0; i<url.length; i++) {
           
            HttpMethod method = HttpMethod.GET;
            Class<String> responseType = String.class;
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.TEXT_PLAIN);
            HttpEntity<String> requestEntity = new HttpEntity<>("params", headers);
            //la llave es la misma url (modificable)
           
            // usar DeferredResult ?
            ListenableFuture<ResponseEntity<String>> future = artf.exchange(url[i], method, requestEntity, responseType);
                   

            // es "opcional"
            future.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() {
                  @Override
                  public void onSuccess(ResponseEntity<String> result) {
                    System.out.println("onSuccess " + result.getHeaders() );
                    //TODO: DeferredResult ?
                  }

                  @Override
                  public void onFailure(Throwable ex) {
                    System.out.println("onFailure!!! " + ex );
                  }
                });
               
             futures.put(url[i], future);
        }

       
        //TODO: borrar !
        // duermo los hilos solo por prueba:
        int segundos_sleep = 2;
        System.out.println("durmiendo por " + segundos_sleep + " segundos...");
        Thread.sleep(segundos_sleep * 1000);

       
        int i=0;
        //voy uno a uno... con Guava SuccessfulAsList seria lo mismo al final ya que quiero cada uno de los responses
        for (Map.Entry<String, ListenableFuture<ResponseEntity<String>>> llave : futures.entrySet()) {
           
            System.out.println((++i)+". -----------------------------------------------------\n");

            System.out.println("key = " + llave.getKey() + ",\n value = " + llave.getValue());
   
            ListenableFuture<ResponseEntity<String>> future = llave.getValue();
            ResponseEntity<String> entity = null;

            try {
           
            entity = future.get(); // blocking en cada uno, pero la respuesta ya puede existir
            } catch (InterruptedException ie) {
                ie.printStackTrace();
                continue;
            } catch (ExecutionException ee) {
                ee.printStackTrace();
                continue;
            }
               
           
            String headers = entity.getHeaders().toString();
           
            if(headers.indexOf("domain=")!=-1)
                System.out.println(headers.substring(headers.indexOf("; domain=")));
            else                
                System.out.println(headers);

            System.out.println(entity.getStatusCode());
            //System.out.println(entity.getBody());
            respuestas.add(entity.getBody().toString());
           
            System.out.println("isDone? " + future.isDone() + "\n");
        }
          

       
        System.out.println("\nfin.");
   

        //return respuestas;
        return "done";
    }

  


19 August 2019

Hungarian algorithm

When there are rows/columns, where each row is a job and each row is a worker.

We need to find the lowest cost to pair (row, column):


Job 1 Job 2 Job 3
Worker 1
2 3 3
Worker 2
3 2 3
Worker 3
3 3 2

Solution: 2, 2, 2 = 6


19 July 2019

Service migration

Co-exist different endpoints for migration purposes. It will be good to apply: Strangler Pattern: Service Migration Strategy.


UPDATE1 (14.04.2021): There are other writings from Fowler about the approach of this strategy (different names, with some minor changes).

https://www.martinfowler.com/bliki/ParallelChange.html (The API expand-contract pattern)

https://martinfowler.com/articles/consumerDrivenContracts.html

 


01 July 2019

Continuous: Integration --> Delivery --> Deployment

Continuous integration:  The concept here is to have multiple devs on a project to keep the main branch of the repo to the most current form of the source code, so each dev can check out or pull from the latest code to avoid conflicts.

Continuous integration puts a great emphasis on testing automation to check that the application is not broken whenever new commits are integrated into the main branch.

Continuous Delivery is a small build cycle with short sprints…
Where the aim is to keep the code in a deployable state at any given time. This does not mean the code or project is 100% complete, but the feature sets that are available are vetted, tested, debugged and ready to deploy, although you may not deploy at that moment.  The focus and key here are to keep the code base at a deployable state.

Continuous delivery is an extension of continuous integration to make sure that you can release new changes to your customers quickly in a sustainable way.

Continuous Deployment, every change that is made is automatically deployed to production.
Continuous deployment goes one step further than continuous delivery.

https://stackify.com/continuous-delivery-vs-continuous-deployment-vs-continuous-integration/
https://www.atlassian.com/continuous-delivery/principles/continuous-integration-vs-delivery-vs-deployment

19 June 2019

Contention RollingFileManager.checkRollover()

Contention at: org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover()

This is a problem with high concurrency, and it works as designed. The file system (I/O) doesn't have  enough performance as required.

The synchronized makes BLOCKED some Java monitor when trying to acquire the resource.
 
/**
 * Determines if a rollover should occur.
 * @param event The LogEvent.
 */
public synchronized void checkRollover(final LogEvent event) {
    if (triggeringPolicy.isTriggeringEvent(event)) {
        rollover();
    }
}

The solution as mentioned above is to move to Async logging.
https://logging.apache.org/log4j/2.x/manual/async.html

JMC Events

From the Event Types tab, look at the color of each event.

Yellow represents Java Monitor Wait events.
The yellow part is when threads are waiting for an object. This often means that the thread is idle, perhaps waiting for a task.

Red represents the Java Monitor Blocked events or synchronization events. If your Java application's important threads spend a lot of time being blocked, then that means that a critical section of the application is single threaded, which is a bottleneck.

Blue represents the Socket Reads and Socket Writes events. Again, if the Java application spends a lot of time waiting for sockets, then the main bottleneck may be in the network or with the other machines that the application communicates.


https://docs.oracle.com/javase/10/troubleshoot/troubleshoot-performance-issues-using-jfr.htm

http://java-performance.info/oracle-java-mission-control-overview/#more-921

10 May 2019

Fallacies of distributed computing

The fallacies are:[1]

Although, there are some writings about they are not fallacies anymore... 

07 May 2019

HTTP 1.0 Performance


HTTP 1.0 had performance issues by slow-start of TCP. The 3-way handshaking was guilty.


https://devwebcl.blogspot.com/2018/09/tcpip-illustrated.html

This was fixed in HTTP 1.1 reusing the connections. Similar to a pool of TCP connections.

2.

  • Under HTTP 1.0, connections are not considered persistent unless a keepalive header is included,[1]

    -Dhttp.keepAlive=false (it can be configured at java system property)

  •  In HTTP 1.1, all connections are considered persistent unless declared otherwise.[2]


Resources:

- https://www.w3.org/Protocols/HTTP/1.0/HTTPPerformance.html
- https://hpbn.co/http1x/
- https://blog.insightdatascience.com/learning-about-the-http-connection-keep-alive-header-7ebe0efa209d
- https://en.wikipedia.org/wiki/HTTP_persistent_connection#HTTP_1.0
- https://en.wikipedia.org/wiki/TCP_congestion_control


02 May 2019

HTTP client timeouts

https://docs.spring.io/autorepo/docs/spring-framework/4.1.7.RELEASE/javadoc-api/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.html

        HttpComponentsClientHttpRequestFactory requestFactory =
                new HttpComponentsClientHttpRequestFactory();

        requestFactory.setConnectionRequestTimeout(connectRequestTimeout);
        requestFactory.setConnectTimeout(connectTimeout);
        requestFactory.setReadTimeout(readTimeout);

       


setConnectionRequestTimeout(int connectionRequestTimeout)
Set the timeout in milliseconds used when requesting a connection from the connection manager using the underlying HttpClient.
(del manager!, del http pool, si no tiene conexiones para ofrecer)


setConnectTimeout(int timeout)
Set the connection timeout for the underlying HttpClient.
(conexion con el server)


setReadTimeout(int timeout)
Set the socket read timeout for the underlying HttpClient.
(lectura del response).

26 April 2019

Hipérbaton

Del lat. hyperbăton, y este del gr. ὑπερβατόν hyperbatón.
 
1. m. Ret. Alteración del orden que las palabras tienen habitualmente en el discurso, como en por mi mano plantado tengo un huerto.

 

11 April 2019

Knuth Quilt

A quick straightforward (and slow) ruby code to create Knuth quilt from Donald Knuth's TAoCP Pre-Fascicle 1a: Bitwise Tricks and Techniques


https://dzone.com/articles/patchwork-quilt-pattern-ruby

 


 

26 March 2019

Proof of Concept (POC)

POC is therefore a prototype that is designed to determine feasibility, but does not represent deliverables.

Persistence, Affinity, Sticky session and others


Affinity: this is when we use information from a layer below the application layer to maintain a client request to a single server

Persistence: this is when we use Application layer information to stick a client to a single server

sticky session: a sticky session is a session maintained by persistence

The main advantage of the persistence over affinity is that it’s much more accurate, but sometimes, Persistence is not doable, so we must rely on affinity.

Using persistence, we mean that we’re 100% sure that a user will get redirected to a single server.

Using affinity, we mean that the user may be redirected to the same server…

https://www.haproxy.com/blog/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/

More info:

https://stackoverflow.com/questions/2528935/sending-cookie-with-http-request-in-java

https://stackoverflow.com/questions/4166129/apache-httpclient-4-0-3-how-do-i-set-cookie-with-sessionid-for-post-request

https://docs.oracle.com/cd/E24329_01/web.1211/e21049/sessions.htm#WBAPP323

https://stackoverflow.com/questions/4166129/apache-httpclient-4-0-3-how-do-i-set-cookie-with-sessionid-for-post-request

https://docs.oracle.com/cd/E24329_01/web.1211/e24425/bigip.htm#CLUST574

https://docs.oracle.com/cd/E11035_01/wls100/cluster/load_balancing.html#wp1028843
https://devcentral.f5.com/questions/sticky-session-for-cookiless-clients  (cooki-less) !!!

https://community.oracle.com/thread/3379174

https://serverfault.com/questions/903386/apache-balancing-towards-weblogic-backends-mod-wl-vs-mod-proxy-balancer

16 March 2019

The History of Computer Chess: An AI Perspective

Very impressive talk with chess authorities and computer scientists.

David Levy, Knuth (talking about its paper alpha-beta).


08 March 2019

Decompiling Java

Simple example:

public class Hola {

    public static void main(String[] args) {


        double pi = 3.14156;
       
        System.out.println("pi="+pi);
       
    }
}


Using javap -c can be solved:

$ javap -c Hola.class Compiled from "Hola.java"
public class Hola {
  public Hola();
    Code:
       0: aload_0      
       1: invokespecial #8                  // Method java/lang/Object."":()V
       4: return       

  public static void main(java.lang.String[]);
    Code:
       0: ldc2_w        #16                 // double 3.14156d
       3: dstore_1     
       4: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
       7: new           #24                 // class java/lang/StringBuilder
      10: dup          
      11: ldc           #26                 // String pi=
      13: invokespecial #28                 // Method java/lang/StringBuilder."":(Ljava/lang/String;)V
      16: dload_1      
      17: invokevirtual #31                 // Method java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
      20: invokevirtual #35                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      23: invokevirtual #39                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
      26: return       
}



javap -verbose MyClass | grep "major"
to know java version.
 


25 February 2019

common log4j2/slf4 error by duplication

####<Nov 23, 2018 12:20:05 PM CLST> <Error> <Deployer> <machine1> <WLSSandbox01> <[STANDBY] ExecuteThread: '3' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1542986405456> <BEA-149231> <Unable to set the activation state to true for the application "foo-bar-qux-rest".
weblogic.application.ModuleException: java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:73)
    at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24)



---


<Feb 22, 2019 1:14:48,804 PM CLST> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: weblogic.application.ModuleException: java.lang.IncompatibleClassChangeError: Class org.apache.logging.slf4j.Log4jLoggerFactory does not implement the requested interface org.slf4j.ILoggerFactory
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)

15 February 2019

Haskell Ubuntu install

sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:hvr/ghc
sudo apt-get update
sudo apt-get install ghc-8.6.3

sudo apt-get install cabal-install-2.4


i.e.:
export PATH=/opt/ghc/8.0.2/bin/:$PATH
export PATH=/opt/ghc/bin/:$PATH

multiple ghc:
$ activate-hs
You must be root to activate a particular Haskell Platform.
Please rerun this command sudo:
    sudo /usr/local/bin/activate-hs 


16 January 2019

Log4j2 name JMX MBeans

To let name through JMX at MBeans, this can be assigned through

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
            <version>${log4j2.version}</version>
            <scope>provided</scope>
        </dependency>
      
and can be customized:

    <context-param>
        <param-name>log4jContextName</param-name>
        <param-value>spring-mvc-simple-32-nombre</param-value>
    </context-param>


https://logging.apache.org/log4j/2.x/manual/webapp.html

It must be web.xml 3.0

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.