
import sys
import os
import glob
#sys.path.append(os.path.join(os.path.dirname(__file__), "gen-py"))
sys.path.append(os.path.join(os.path.dirname(__file__),"gen-py/thrift_solr/"))
sys.path.append(os.path.dirname(__file__) )

from thrift.transport import TSocket 
from thrift.server import TServer 
#import thrift_solr


import ExtractorService

import sys

import readability

import readability

def extract_with_python_readability( raw_content ):
    doc = readability.Document( raw_content )
    
    return [ u'' + doc.short_title(),
             u'' + doc.summary() ]

class ExtractorHandler:
    def extract_html( self, raw_html ):

        #print raw_html

        #raw_html = raw_html.encode( 'utf-8' )

        ret =  extract_with_python_readability( raw_html )
        #print ret[1]
        return ret

handler = ExtractorHandler()
processor = ExtractorService.Processor(handler)
listening_socket = TSocket.TServerSocket(port=9090)
server = TServer.TThreadPoolServer(processor, listening_socket)

print ("[Server] Started")
server.serve()


import sys
import os
import glob
#sys.path.append(os.path.join(os.path.dirname(__file__), "gen-py"))
sys.path.append(os.path.join(os.path.dirname(__file__),"gen-py/thrift_solr/"))
sys.path.append(os.path.dirname(__file__) )

from thrift.transport import TSocket 
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer 
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAccelerated

#import thrift_solr


import ExtractorService

import sys

import readability

import readability

def extract_with_python_readability( raw_content ):
    doc = readability.Document( raw_content )
    
    return [ u'' + doc.short_title(),
             u'' + doc.summary() ]

class ExtractorHandler:
    def extract_html( self, raw_html ):

        #print raw_html

        #raw_html = raw_html.encode( 'utf-8' )

        ret =  extract_with_python_readability( raw_html )
        #print ret[1]
        return ret

handler = ExtractorHandler()
processor = ExtractorService.Processor(handler)
listening_socket = TSocket.TServerSocket(port=9090)
tfactory = TTransport.TBufferedTransportFactory()
#pfactory = TBinaryProtocol.TBinaryProtocolFactory()
pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()

server = TServer.TThreadPoolServer(processor, listening_socket, tfactory, pfactory)

print ("[Server] Started")
server.serve()

Use the TBinaryProtocolAccelerated protocol instead of TBinaryProtocol to improve performance.
Use the TBinaryProtocolAccelerated protocol instead of TBinaryProtocol to improve performance.

  
  import sys
  import os
  import glob
  #sys.path.append(os.path.join(os.path.dirname(__file__), "gen-py"))
  sys.path.append(os.path.join(os.path.dirname(__file__),"gen-py/thrift_solr/"))
  sys.path.append(os.path.dirname(__file__) )
  
  from thrift.transport import TSocket 
+ from thrift.transport import TTransport
+ from thrift.protocol import TBinaryProtocol
  from thrift.server import TServer 
+ from thrift.protocol.TBinaryProtocol import TBinaryProtocolAccelerated
+ 
  #import thrift_solr
  
  
  import ExtractorService
  
  import sys
  
  import readability
  
  import readability
  
  def extract_with_python_readability( raw_content ):
      doc = readability.Document( raw_content )
      
      return [ u'' + doc.short_title(),
               u'' + doc.summary() ]
  
  class ExtractorHandler:
      def extract_html( self, raw_html ):
  
          #print raw_html
  
          #raw_html = raw_html.encode( 'utf-8' )
  
          ret =  extract_with_python_readability( raw_html )
          #print ret[1]
          return ret
  
  handler = ExtractorHandler()
  processor = ExtractorService.Processor(handler)
  listening_socket = TSocket.TServerSocket(port=9090)
+ tfactory = TTransport.TBufferedTransportFactory()
+ #pfactory = TBinaryProtocol.TBinaryProtocolFactory()
+ pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()
+ 
- server = TServer.TThreadPoolServer(processor, listening_socket)
+ server = TServer.TThreadPoolServer(processor, listening_socket, tfactory, pfactory)
  
  print ("[Server] Started")
  server.serve()
  
Use the TBinaryProtocolAccelerated protocol instead of TBinaryProtocol to improve performance.
## Code Before:

import sys
import os
import glob
#sys.path.append(os.path.join(os.path.dirname(__file__), "gen-py"))
sys.path.append(os.path.join(os.path.dirname(__file__),"gen-py/thrift_solr/"))
sys.path.append(os.path.dirname(__file__) )

from thrift.transport import TSocket 
from thrift.server import TServer 
#import thrift_solr


import ExtractorService

import sys

import readability

import readability

def extract_with_python_readability( raw_content ):
    doc = readability.Document( raw_content )
    
    return [ u'' + doc.short_title(),
             u'' + doc.summary() ]

class ExtractorHandler:
    def extract_html( self, raw_html ):

        #print raw_html

        #raw_html = raw_html.encode( 'utf-8' )

        ret =  extract_with_python_readability( raw_html )
        #print ret[1]
        return ret

handler = ExtractorHandler()
processor = ExtractorService.Processor(handler)
listening_socket = TSocket.TServerSocket(port=9090)
server = TServer.TThreadPoolServer(processor, listening_socket)

print ("[Server] Started")
server.serve()

## Instruction:
Use the TBinaryProtocolAccelerated protocol instead of TBinaryProtocol to improve performance.
## Code After:

import sys
import os
import glob
#sys.path.append(os.path.join(os.path.dirname(__file__), "gen-py"))
sys.path.append(os.path.join(os.path.dirname(__file__),"gen-py/thrift_solr/"))
sys.path.append(os.path.dirname(__file__) )

from thrift.transport import TSocket 
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer 
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAccelerated

#import thrift_solr


import ExtractorService

import sys

import readability

import readability

def extract_with_python_readability( raw_content ):
    doc = readability.Document( raw_content )
    
    return [ u'' + doc.short_title(),
             u'' + doc.summary() ]

class ExtractorHandler:
    def extract_html( self, raw_html ):

        #print raw_html

        #raw_html = raw_html.encode( 'utf-8' )

        ret =  extract_with_python_readability( raw_html )
        #print ret[1]
        return ret

handler = ExtractorHandler()
processor = ExtractorService.Processor(handler)
listening_socket = TSocket.TServerSocket(port=9090)
tfactory = TTransport.TBufferedTransportFactory()
#pfactory = TBinaryProtocol.TBinaryProtocolFactory()
pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()

server = TServer.TThreadPoolServer(processor, listening_socket, tfactory, pfactory)

print ("[Server] Started")
server.serve()
