How to change Mina NioProcessor thread names - apache-mina

I want to change mina NioProcessor thread names because when I print thread names using log4j, they aren't very meaningful to me (e.g. NioProcessor-36, NioProcessor-42) especially when there are multiple Processors around. Is it possible?

Below solution offers custom thread names after NioProcessor threads.
Create a custom thread factory which gives your desired names to new threads. Here is an example how to do this.
Create an executor filter like below
Executor executor = Executors.newFixedThreadPool(1, new YourThreadFactory("namingConvention"))
acceptor.getFilterChain().addFirst("executor", executor)
If you already have an executor filter, then you will just give a thread factory as parameter.

Related

How to share/pass a variable among multiple thread groups within jmeter and without using beanshell assertion

I have declared 1 user defined variable (A=wait) in a test plan and I have 2 thread groups in the test plan. When 1st thread group completes it's execution then I have changed the value to "go" (A=go) using beanshell post processor. Now, in second thread group I want that (A) should be pick the updated value (means "go" not "wait") but I am not able to pick the updated value in 2nd thread group. I am not using any regular expression extractor, just using and updating user defined variable.
I tried beanshell pre and post processor. First I created 1 bean shell sampler in which I changed the value(vars.put("A1","go");) then I created 1 beanshell postprocessor (${__setProperty(A,${A1})}) in first thread group and then in 2nd thread group I added BeanShell preprocessor to get the value (${__property(A)})
I also used beanshell assertion to pass the variable to next thread group but next thread group didn't catched the updated value.
If you don't want to use scripting - take a look at Inter-Thread Communication Plugin
There is an example test plan showing how variables could be shared.
Going forward be aware that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting and in Groovy you should avoid inlining JMeter Functions or Variables
So:
In first thread group:
props.put('A', 'go')
In second thread group:
go = props.get('A')
or if you prefer a function:
${__P(A,)}
Demo:

What's the best way to get HTable handle of HBase?

One way is directly call the HTable constructor, another is to call the getTable method from a HConnection. The second option requires the HConnection to be "unmanaged", which is not very good for me because my process will have many threads accessing HBase. I don't want to re-invent the wheel to manage the HConnections on my own.
Thanks for your help.
[Updates]:
We are stuck with 0.98.6, so ConnectionFactory is not available.
I found the bellow jira suggesting to create an "unmanaged" connection and use a single ExecuteService to create HTable. Why can't we simply use the getTable method of the unmanaged connection to get HTable? Is that because of HTable is not thread safe?
https://issues.apache.org/jira/browse/HBASE-7463
Im stuck with old versions (<0.94.11) in which you can still use HTablePool but since it has been deprecated by HBASE-6580 I think requests from HTables to the RS are now automatically pooled by providing an ExecutorService:
ExecutorService executor = Executors.newFixedThreadPool(10);
Connection connection = ConnectionFactory.createConnection(conf, executor);
Table table = connection.getTable(TableName.valueOf("mytable"));
try {
table.get(...);
...
} finally {
table.close();
connection.close();
}
I've been unable to find any good examples/docs about it, so please notice this is untested code which may not work as expected.
For more information you can take a look to the ConnectionFactory documentation & to the JIRA issue:
https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/ConnectionFactory.html
https://issues.apache.org/jira/browse/HBASE-6580
Update, since you're using 0.98.6 and ConnectionFactory is not available you can use HConnectionManager instead:
HConnection connection = HConnectionManager.createConnection(config); // You can also provide an ExecutorService if you want to override the default one. HConnection is thread safe.
HTableInterface table = connection.getTable("table1");
try {
// Use the table as needed, for a single operation and a single thread
} finally {
table.close();
connection.close();
}
HTable is not thread safe so you must make sure you always get a new instance (it's a lightweight process) with HTableInterface table = connection.getTable("table1") and close it afterwards with table.close().
The flow would be:
Start your process
Initialize your HConnection
Each thread:
3.1 Gets a table from your HConnection
3.2 Writes/reads from the table
3.3 Closes the table
Close your HConnection when your process ends
HConnectionManager: http://archive.cloudera.com/cdh5/cdh/5/hbase/apidocs/org/apache/hadoop/hbase/client/HConnectionManager.html#createConnection(org.apache.hadoop.conf.Configuration)
HTable: http://archive.cloudera.com/cdh5/cdh/5/hbase/apidocs/org/apache/hadoop/hbase/client/HTable.html

does newfixedthreadpool create a blockignqueue internally

When i use Executors.newFixedThreadPool(10), does the framework internally create a blockingqueue? Is there a way to supply my own queue while creating the thread pool? It is not clear to me from the oracle docs:here
Yes, it does, as found here.
Usually you do want a blocking queue, as the purpose of the queue is to hold on to jobs to prevent overwhelming Executor. You could implement your own Executor + ExecutorService and use your custom queue in there, or, you could use a ThreadPoolExecutor with your impl, similar to this:
88 public static ExecutorService More ...newFixedThreadPool(int nThreads) {
89 return new ThreadPoolExecutor(nThreads, nThreads,
90 0L, TimeUnit.MILLISECONDS,
91 new LinkedBlockingQueue<Runnable>());
92 }
If the queue isn't blocking, then you'll start rejecting tasks, as mentioned here.

How can i partition the threads by their percent

I wanna slice the threads by their percent. For example :
- My Test Plan
-SignUp Thread (this task should be %10)
-LogIn Thread (this task should be %40)
-Search Thread (this task should be %30)
-Add New Topic (this task should be %20)
How can i do this partition ?
Thanks
You can possibly use set of Throughput Controllers - but they will work properly only in loop (as "children" of Loop Controller e.g.).
Look into these for details:
Purpose of Throughput Controller?
Jmeter - weighted random values?
How throughput controller work?

getting the thread id of threads in the threadpool from outside threadprocessing method

I am implementing multi-threading concepts using thread-pooling to pick up messages from queues. There is a necessity that the id/number of the thread which picks up a particular message has to be accessed from outside the thread method. Supposes if there are three threads and they have to pick up 5 messages from the queue. the first thread picks up the first message processes it and it is released. meanwhile the second thread would have picked up some other message and would've started to process it(multi-threading).
Here from some other method, i want to know which thread actually picks up message1, and the consistency has to maintained not only inside the threading function but throughout the application(from outside the thread function also).
i have implemented multi-threading as follows
For m_intThread1 = 0 To m_stuTPConfig.intNumThreads - 1
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf **MultiProcessMQ**), m_intThread1)
System.Threading.Thread.Sleep(1000)
Next m_intThread1 'm_intThread
Public Shared Sub MultiProcessMQ(ByVal state As Object)
Dim objParentProcess As New ParentProcess
objParentProcess.ProcessThread(CType(state, String))
If Interlocked.Decrement(CInt(m_stuTPConfig.intNumThreads)) = 0 Then
m_asyncOpsAreDone.Set()
End If 'Interlocked.Decrement(CInt(m_stuTPConfig.intNumThreads)) = 0
End Sub 'MultiProcessMQ()
Public Sub ProcessThread(ByVal strThread As String)
intThrd = Convert.ToInt32(strThread)
Console.WriteLine("Parent Thread started " & strThread)
End Sub
How do i access the variable strThread From another method and maintain its consistency.This is required for logging purposes.
Thanks for formatting. We are using WCFMQAdapter services which is a for configuring the app in accordance with the input and output queues. once I host this service from ProcessThread the control goes to some other file, say a service.vb file wherein all the operations pertaining to the thread are performed and never comes back. The actual usage of threads here are for logging the processing details onto a file in the service.vb file. Now the PROCESSTHREAD method is called. till now the multithreading properties are maintained. once the service is hosted how to pass on these thread info to the service.vb. Or should there be a parent threading/child threading concept? And, if i obtain a threadid using managedThreadId, dynamic thread ids are generated. Are there any chances to obtain them and convert it into user managed ids. say, instead of thread 21,thread 44,thread66,thread89........ can we convert them like thread1, thread 2, thread 3, thread 4? Thanks in Advance :-)
You can use System.Threading.Thread.CurrentThread.ManagedThreadId to get a unique id for each thread. I'd use that to identify your threads.