Friday, April 24, 2015

Fixing Python Related Error While Installing Cassandra

Cassandra requires Python to be installed in your machine. So you might have downloaded and installed latest version of Python 3.x series. But still when you are trying to install setup.py from Cassandra pylib, you are getting errors. I tried to do it in my Windows machine and got error similar to below logs:
    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\cqlhandling.py to cqlhandling.cpython-34.pyc

      File "D:\test\software\python\Lib\site-packages\cqlshlib\cqlhandling.py", line 240

        print "cql_complete(%r, partial=%r)" % (text, partial)

                                           ^

    SyntaxError: invalid syntax


    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\displaying.py to displaying.cpython-34.pyc

    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\formatting.py to formatting.cpython-34.pyc

    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\helptopics.py to helptopics.cpython-34.pyc

      File "D:\test\software\python\Lib\site-packages\cqlshlib\helptopics.py", line 27

        print "\n        CQL types recognized by this version of cqlsh:\n"

                                                                         ^

    SyntaxError: Missing parentheses in call to 'print'


    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\meter.py to meter.cpython-34.pyc

      File "D:\test\software\python\Lib\site-packages\cqlshlib\meter.py", line 57

        print ""

               ^

    SyntaxError: Missing parentheses in call to 'print'


    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\pylexotron.py to pylexotron.cpython-34.pyc

      File "D:\test\software\python\Lib\site-packages\cqlshlib\pylexotron.py", line 131

        print "Trying completer %r with %r" % (completer, ctxt)

                                          ^

    SyntaxError: invalid syntax


    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\saferscanner.py to saferscanner.cpython-34.pyc

    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\sslhandling.py to sslhandling.cpython-34.pyc

    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\tracing.py to tracing.cpython-34.pyc

    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\util.py to util.cpython-34.pyc

    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\wcwidth.py to wcwidth.cpython-34.pyc

      File "D:\test\software\python\Lib\site-packages\cqlshlib\wcwidth.py", line 367

        print 'tests pass.'

                          ^

    SyntaxError: Missing parentheses in call to 'print'


    byte-compiling D:\test\software\python\Lib\site-packages\cqlshlib\__init__.py to __init__.cpython-34.pyc

    running install_egg_info

    Writing D:\test\software\python\Lib\site-packages\cassandra_pylib-0.0.0-py3.4.egg-info
This is because Cassandra supports Python 2.x series. So uninstall Python 3 from your machine and install latest version of Python 2. Then try to run "python setup.py install" command again. It should run just fine without any errors.

Wednesday, April 22, 2015

What Does Java Thread State WAITING (parking) In Thread Dump Mean

If you are new to thread dump analysis, you might become confused with this Java thread state WAITING (parking). If a Java thread is in waiting state, that means it is waiting for another thread to call notify on the same object. And if you see too many threads waiting in your thread dump, you will assume there is some issue and that is causing your server to hang. But there is a common case where WAITING (parking) thread state might not be the actual issue. Look at below:
"pool-1-thread-22" prio=5 tid=101b4b000 nid=0x127122000 waiting on condition [127121000]
   java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <6c340cee0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
You will see same kind of pool threads with status waiting (parking). These are basically request worker threads on a tomcat sever. These are waiting on a blocking queue until a request comes. When a request comes, one thread will get permit and will run to execute the request.
Same thing will happen when you use your own Java ThreadPoolExecutor. It will create a pool of threads and those threads will wait on a blocking queue provided to the executor. Task executor uses this queue to push and pop tasks as and when they are submitted. So if no tasks are available these threads will wait (park) on the queue. When a task is available, one worker thread will get permit and become a running thread. It will execute the task.
So don't get overwhelmed with waiting (parking) threads. These threads still can cause issue if you have created too many threads in your thread pool and they are eating up your resource. Otherwise you are fine. Your threads are not locked on some object.

Sunday, April 12, 2015

Use NotePad++ As Offline JSON Viewer

Most of us use online JSON viewers like JSON Lint. But the issue creeps in when you have to parse and view somewhat big text file like 3-4 mb. Then JSON Lint page starts to hang and after some time your whole browser including other tabs goes into not responding mode whether it is Firefox or Google Chrome. At least that is the case that happens in my laptop. http://jsonviewer.stack.hu/ online viewer performs a lot better in handling big JSON files than JSON Lint. But I was also looking for an offline JSON viewer. And I found out that NotePad++ has a JSON viewer plugin. I installed it and it handles big files quite well. It will just try to parse the text and show it in tree view. And good thing is, you can keep on browsing when NotePad++ is busy in formatting your JSON. You don't have to worry about web browser crash.