[ 
https://issues.apache.org/jira/browse/SOLR-10390?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15947849#comment-15947849
 ] 

Felipe Gasper commented on SOLR-10390:
--------------------------------------

Even the Perl one-liner is also palpably faster than lsof:

{code}
root@felipe64 15:40:05 ~
> time lsof -PniTCP:8984 -sTCP:LISTEN
COMMAND   PID       USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
java    12700 cpanelsolr  111u  IPv6 17585217      0t0  TCP 127.0.0.1:8984 
(LISTEN)

real    0m0.056s
user    0m0.007s
sys     0m0.050s

OK
root@felipe64 15:40:11 ~
> time perl -MSocket -e'die "Need host & port!" if @ARGV < 2; socket( my $s, 
> AF_INET, SOCK_STREAM, 0) or die $!; connect( $s, sockaddr_in($ARGV[1], 
> inet_aton($ARGV[0])) ) or die $!; print "OK\n"' localhost 8984
OK

real    0m0.012s
user    0m0.008s
sys     0m0.004s
{code}

> lsof has too many kernel dependencies
> -------------------------------------
>
>                 Key: SOLR-10390
>                 URL: https://issues.apache.org/jira/browse/SOLR-10390
>             Project: Solr
>          Issue Type: Bug
>      Security Level: Public(Default Security Level. Issues are Public) 
>            Reporter: Felipe Gasper
>
> lsof seems a very "heavy" solution for just checking whether a socket is 
> open. In Linux in particular it's problematic because there are kernel 
> options that will break lsof, e.g. CloudLinux's *kernel.user_ptrace* and 
> *kernel.user_ptrace_self* options.
> If all that's needed here is a simple connect() to the socket, what about 
> shipping something simple like this:
> {code}
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <netdb.h>
> void _fail() {
>     exit(EXIT_FAILURE);
> }
> void error(const char *msg) {
>     perror(msg);
>     _fail();
> }
> int main(int argc, char *argv[]) {
>     int sockfd, portno, n;
>     struct sockaddr_in serv_addr;
>     struct hostent *server;
>     char buffer[256];
>     if (argc < 3) {
>        fprintf(stderr,"usage %s hostname port\n", argv[0]);
>         _fail();
>     }
>     portno = atoi(argv[2]);
>     sockfd = socket(AF_INET, SOCK_STREAM, 0);
>     if (sockfd < 0) {
>         error("ERROR opening socket");
>     }
>     server = gethostbyname(argv[1]);
>     if (server == NULL) {
>         fprintf(stderr,"ERROR: no such host\n");
>         _fail();
>     }
>     bzero((char *) &serv_addr, sizeof(serv_addr));
>     serv_addr.sin_family = AF_INET;
>     bcopy((char *)server->h_addr,
>          (char *)&serv_addr.sin_addr.s_addr,
>          server->h_length);
>     serv_addr.sin_port = htons(portno);
>     if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) 
> {
>         error("ERROR connecting");
>     }
>     fprintf(stdout, "OK\n");
>     return EXIT_SUCCESS;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to