24 January 2020

14 January 2020

lsof tips & tricks

pid from port
lsof -i @192.14.166.72:20000

open jar files:
lsof -p | grep jar

Get the list of files opened
lsof –p

Get the count
lsof –p | wc –l

pid listening tcp at specific port:
lsof -i tcp:8888

From gist

#list all ports for tcp
sudo lsof -itcp

#find all things listening on ports
lsof -Pnl +M -i4 | grep LISTEN

#all ports for tcp, dont resolve port name from numbers
sudo lsof -itcp -P

#open files and ports of process #$PID
sudo lsof -p $PID

#only ports of tcp for process #$PID, dont resolve port name, dont resolve ip name
sudo lsof -a -p $PID -P -n -itcp

#only ports of tcp for process #$PID, dont resolve port name, dont resolve ip name, refresh every 5 seconds
sudo lsof -a -p $PID -P -n -itcp -r 5

#search by file (can be slow)
sudo lsof /complete/path/to/file

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



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.




06 November 2019

Eclipse - spaces instead of tabs

Usually when using a new eclipse version or AnyEdit Tools.

Always I forget to change this and the impact is huge in git.



My Blog List

Blog Archive

Disclaimer

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