BewareMyPower edited a comment on issue #9796:
URL: https://github.com/apache/pulsar/issues/9796#issuecomment-803039329
Sorry to tell you the bad news that I still cannot reproduce it on CentOS 7.
The only difference is that I just used a single C++ source file to simulate
your CMake project.
```c++
#include <iostream>
#include <thread>
#include <pulsar/Client.h>
using namespace pulsar;
void callback(Result code, const MessageId& msgId) {
std::cout << "Received code: " << code << " -- MsgID: " << msgId <<
std::endl;;
}
int main() {
auto client = new Client("pulsar://localhost:6650");
Producer producer;
Result result = client->createProducer("my-topic", producer);
if (result != ResultOk) {
std::cerr << "Error creating producer: " << result << std::endl;
return -1;
}
for (int i = 0; i < 10000; i++) {
Message msg =
MessageBuilder().setContent("content").setProperty("x", "1").build();
producer.sendAsync(msg, callback);
}
client->close();
delete client;
return 0;
}
```
And see the following content for the detail experiment process.
### 1. Prepare CentOS 7 environment
First, pull a CentOS 7 docker image and run it.
```bash
$ docker pull centos:7.6.1810
$ docker run -itd centos:7.6.1810
2e2000ebc6d2b90a2798b44eec50578a2e98a682c15a564eb5536b6629fc4eae
$ docker exec -it 2e2000 /bin/bash
```
### 2. Copy necessary files
Copy the `apache-pulsar-2.7.0-bin`, `pulsar-2.7.0/pulsar-client-cpp/include`
and your provided library to the `/root` directory. After this step, you can see
```bash
# cd /root/
# ls include/pulsar/
Authentication.h ClientConfiguration.h ConsumerConfiguration.h
CryptoKeyReader.h InitialPosition.h Message.h MessageId.h
ProducerConfiguration.h ReaderConfiguration.h TopicMetadata.h
BrokerConsumerStats.h CompressionType.h ConsumerCryptoFailureAction.h
DeprecatedException.h KeySharedPolicy.h MessageBatch.h
MessageRoutingPolicy.h ProducerCryptoFailureAction.h Result.h c
Client.h Consumer.h ConsumerType.h
EncryptionKeyInfo.h Logger.h MessageBuilder.h Producer.h
Reader.h Schema.h defines.h
# ls -l lib/
total 60628
lrwxrwxrwx 1 root root 18 Jan 26 01:31 libpulsar.so ->
libpulsar.so.2.7.0
-rwxr-xr-x 1 root root 62079528 Jan 26 01:31 libpulsar.so.2.7.0
```
I only used `libpulsar.so`.
### 3. Run pulsar standalone
You should install JDK8 first:
```bash
# yum update
# yum install -y java-1.8.0-openjdk.x86_64
```
Then start the standalone
```bash
# cd /root/apache-pulsar-2.7.0/
# bin/pulsar standalone
````
### 4. Build and run C++ program
Open a new terminal to login the docker container. Then create a new file
`/root/main.cc` whose content is the C++ code I gave. You can simply use `cat
>> main.cc` command and paste your code.
Install GCC first:
```bash
# yum install -y gcc gcc-c++
```
Build and run the program:
```bash
# cd /root
# export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
# g++ main.cc -std=c++11 -I include/ -L lib/ -lpulsar
# ./a.out
```
I've run for several times, no segmentation fault happened. And I also tried
to redirect the output to a log file:
```bash
# ./a.out > 1.log
# grep "Ok" 1.log | wc -l
7000
# grep "Full" 1.log | wc -l
2761
```
You can see among these 10000 messages, 2761 messages were sent
successfully, 7000 messages were failed to sent because queue is full, and
there're 239 messages that lost because we closed the `Client` immediately and
the pending send callbacks were discarded.
I noticed your project has no `sleep` between two `sendAsync`, or between
the last `sendAsync` and `client->close()`. The sending speed is too fast so
that many messages encountered `ProduceQueueIsFull` error because there's no
time for the pending messages in queue to send when your new messages were
`sendAsync` to the queue.
**It seems that you didn't run my code before.** My code uses `sleep` to
control the sending speed, for example, sleeping for 10 milliseconds is
approximately same to sending 100 messages per second. If sending speed is too
fast, the `ProduceQueueIsFull` may happen.
Whatever, even if without `sleep`, from my latest tests, the segmentation
fault still didn't happen.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]